Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when passing INT to web service

Status
Not open for further replies.

proteome

Technical User
May 14, 2003
115
US
I am having a problem when passing a data to a webservice. The web service has three instance variables 2 of type int and one of type string. When I pass data to the web service the int varibles get set to 0 and the string variable is set to the correct data.

ex.
string temp = "Thanks"
int x = 6
int z = 7

when passed to web service

temp = "Thanks"
x = 0
z = 0


THanks
 
Here is an example of another service that doesn't work this takes two intergers and passes them back to a console


<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:soap=" xmlns:tm=" xmlns:soapenc=" xmlns:mime=" xmlns:tns=" xmlns:s=" xmlns:soap12=" xmlns:http=" targetNamespace=" xmlns:wsdl=" - <wsdl:types>
- <s:schema elementFormDefault="qualified"
targetNamespace=" - <s:element name="GetPair">
<s:complexType />
</s:element>
- <s:element name="GetPairResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetPairResult"
type="tns:pair" />
</s:sequence>
</s:complexType>
</s:element>
- <s:complexType name="Pair">
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="x" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="y" type="s:int" />
</s:sequence> </s:complexType> </s:schema> </wsdl:types>
- <wsdl:message name="GetPairSoapIn">
<wsdl:part name="parameters" element="tns:GetPair" />
</wsdl:message>
- <wsdl:message name="GetPairSoapOut"> <wsdl:part name="parameters"
element="tns:GetPairResponse" /> </wsdl:message>
- <wsdl:portType name="ServiceSoap">
- <wsdl:eek:peration name="GetPair">
<wsdl:input message="tns:GetPairSoapIn" /> <wsdl:eek:utput
message="tns:GetPairSoapOut" /> </wsdl:eek:peration> </wsdl:portType>
- <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport=" />
- <wsdl:eek:peration name="GetPair">
<soap:eek:peration soapAction=" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:eek:utput>
<soap:body use="literal" />
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>
- <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport=" />
- <wsdl:eek:peration name="GetPair">
<soap12:eek:peration soapAction=" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:eek:utput>
<soap12:body use="literal" />
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>
- <wsdl:service name="Service">
- <wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">
<soap:address location=" /> </wsdl:port>
- <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">
<soap12:address location=" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
 
How did you make the wsdl file? I cant see where you are associating x and y with the input parameters. (But Im at work, so Ihavent been able to look properly)
 
Ive just imported that wsdl to a project, and instantiated the service call.

that WSDL defines a webservice that returns 2 integers as a 'pair'.

What do you want your webservice to do, are you expecting to call ws(x,y,mystring), or to return a pair of numbers?
 
THis was a test case I have a console app that calls this service and the service should return I believe 5 and 6 but it returns 0 and 0
 
well have you debugged the service? All the wsdl does is say that there is a service that returns a pair.

Can you post the source of the webservice?
 
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public
class Service : System.Web.Services.WebService {
public class Pair
{
public int x;
public int y;
}

public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public Pair GetPair() {
Pair foo = new Pair();
foo.x = 5;
foo.y = 6;
return foo;
}
}

===========================================================

Now write a console application as a client.
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
localhost.Service theService = new localhost.Service();
localhost.Pair thePair = theService.GetPair();
Console.WriteLine(thePair.x);
Console.WriteLine(thePair.y);

}
 
ok, forgive me for going back to basics here, but after the day Ive had, I want to make sure I take nothing for granted.

Ive implemented your service and it works.

can you open up a browser, and go to the url on the webserver where your service is hosted?
(on mine it was
Then click on GetPair(), and chose invoke. You should see something like below.
Code:
<?xml version="1.0" encoding="utf-8" ?> 
<Pair xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns="[URL unfurl="true"]http://tempuri.org/">[/URL]
  <x>5</x> 
  <y>6</y> 
  </Pair>

For what its worth, I only have VS2003, and so dont have the conformsTo Attribute
 
Oh, when you say that the other code doeant work (the console ap. how do you mean it doesnt work?)

It works for me, so long as I modify the code so that the console doesnt disappear the second the pair is output.

K
 
I have figred it out. It seems as if visual studio 2005 doesnt like having multiple projects under one solution when dealing with web services. If I put the console app and the web service in their own project folders everything is happy and the ints are not dropped. Go figure??



THanks for all the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top