Creating a consumer of a Web Service WSDL/SOAP - c#

I am attempting to write a Windows Desktop App (using WCF) that is a consumer of a web service.
The application:
Sends a SOAP message to a British Government Server to get an authentication token based on the arugments passed
Retrieves a response from that server in the form of a string which contains the authentication token.
I have a template of the SOAP message from the British Government, and a WSDL file for the service.
What I have tried
Add a service reference using the WSDL file. I received the following error: URI formats are not supported.
Add a Web Reference using the URL of the service. I received the following error: The request failed with HTTP status 405: Method Not Allowed.
Send the SOAP request using a POST. The Call to GetResponse() threw a 500 External Server Error.
NOTE: I am using VS 2005
WSDL:
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:conv="http://www.openuri.org/2002/04/soap/conversation/" xmlns:cw="http://www.openuri.org/2002/04/wsdl/conversation/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:jms="http://www.openuri.org/2002/04/wsdl/jms/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s1="https://tpvs.hmrc.gov.uk/dpsauthentication" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="https://tpvs.hmrc.gov.uk/dpsauthentication">
<types>
<s:schema elementFormDefault="qualified" targetNamespace="https://tpvs.hmrc.gov.uk/dpsauthentication" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns="https://tpvs.hmrc.gov.uk/dpsauthentication">
<s:element name="DPSrequestToken">
<s:complexType>
<s:sequence>
<s:element name="version" type="s:int"/>
<s:element name="vendorID" type="s:string" minOccurs="0"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="DPSrequestTokenResponse">
<s:complexType>
<s:sequence>
<s:element name="DPSrequestTokenResult" type="s:string" minOccurs="0"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</types>
<message name="DPSrequestTokenSoapIn">
<part name="parameters" element="s1:DPSrequestToken"/>
</message>
<message name="DPSrequestTokenSoapOut">
<part name="parameters" element="s1:DPSrequestTokenResponse"/>
</message>
<portType name="dpsauthenticationSoap">
<operation name="DPSrequestToken">
<input message="s1:DPSrequestTokenSoapIn"/>
<output message="s1:DPSrequestTokenSoapOut"/>
</operation>
</portType>
<binding name="dpsauthenticationSoap" type="s1:dpsauthenticationSoap">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="DPSrequestToken">
<soap:operation soapAction="https://tpvs.hmrc.gov.uk/dpsauthentication/DPSrequestToken" style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="dpsauthentication">
<port name="dpsauthenticationSoap" binding="s1:dpsauthenticationSoap">
<soap:address location="https://dps.ws.hmrc.gov.uk/dpsauthentication/service"/>
</port>
</service>
</definitions>
SOAP:
<!-- v1.1 30/11/2007 -->
<!-- 24/10/2011 - minor change to remove duplicated text from <Envelope> element. No impact on validation, therefore not re-versioned. -->
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>as advised by SDS team</wsse:Username>
<wsse:Password>as advised by SDS team</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:DPSrequestToken xmlns:m="https://tpvs.hmrc.gov.uk/dpsauthentication">
<m:version>1</m:version>
<m:vendorID>your 4 digit vendorID</m:vendorID>
</m:DPSrequestToken>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

In case someone else runs across the same issue, I was able to solve this issue by using the WSDL.exe program that is normally found in 2. C:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\.
This program creates a proxy class for a web service that allows you to call the API's methods localy in your code.
In command line WSDL.exe is called like this: 3.
wsdl http://host/web_service/web_service.asmx?WSDL

Related

Android project can't connect to WCF Web Service

I need to use .Net wcf web service. but I can't success it. I saw error and it is written:
org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null#1:0 in java.io.InputStreamReader#46029560)
Can you help me how I use this web service?
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" name="Service" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import namespace="http://schemas.datacontract.org/2004/07/"/>
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<xs:element name="GetTreatmentValues">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="tID" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">...</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/">...</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays">...</xs:schema>
</wsdl:types>
<wsdl:message name="IService_GetTreatmentValues_InputMessage">
<wsdl:part name="parameters" element="tns:GetTreatmentValues"/>
</wsdl:message>
<wsdl:message name="IService_GetTreatmentValues_OutputMessage">
<wsdl:part name="parameters" element="tns:GetTreatmentValuesResponse"/>
</wsdl:message>
<wsdl:portType name="IService">
<wsdl:operation name="GetTreatmentValues">
<wsdl:input wsaw:Action="http://tempuri.org/IService/GetTreatmentValues" message="tns:IService_GetTreatmentValues_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IService/GetTreatmentValuesResponse" message="tns:IService_GetTreatmentValues_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IService" type="tns:IService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetTreatmentValues">
<soap:operation soapAction="http://tempuri.org/IService/GetTreatmentValues" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service">
<wsdl:port name="BasicHttpBinding_IService" binding="tns:BasicHttpBinding_IService">
<soap:address location="http://192.168.2.7:90/Service.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
My android
private final String NAMESPACE="http://tempuri.org/";
private final String SOAPACTION="http://tempuri.org/GetTreatmentValues";
private final String METHODNAME="GetTreatmentValues";
private final String URL="http://192.168.2.7:90/IService/Service.svc?singleWsdl";
private EditText text1;
private EditText text2;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tansiyon);
Button button1=(Button) findViewById(R.id.button1);
text1 = (EditText) findViewById(R.id.editText1);
text2 = (EditText) findViewById(R.id.editText2);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SoapObject request = new SoapObject(NAMESPACE,METHODNAME);
request.addProperty("tID",1);
SoapSerializationEnvelope sp = new SoapSerializationEnvelope(SoapEnvelope.VER12);
sp.dotNet = true;
sp.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL);
try {
aht.call(SOAPACTION,sp);
text2.setText("test");
} catch (Exception ex) {
// TODO: handle exception
text2.setText("error");
ex.printStackTrace();
}
}
});
}
first off, I assume you didn't forget to add suitable permissions in your app's manifest.
now you have a couple of problems, first you are trying network access in the UI thread which is not allowed by Android for API 12 and up, I expect a "network on main thread exception" to appear in your LogCat. You just have to move the ksoap2 call to an AsyncTask or so.
the other problem which I faced before is that I didn't specify a namespace in my wcf web service, so tempuri.org is put by default and it was not working, I had to change it to something else and use it and then it worked like a charm.
try to solve the first problem and run the app, you may not have a problem with tempuri.org but if it still crash then change the namespace in your service, publish it and run your app again.
In the android code don't append ?WSDL. Just write address up to Service.svc or you can copy the address from <soap:address location="..."/> tag of WSDL file. I hope it might work for you.
Refer the following link for further details:
http://techzusiastic.blogspot.in/2014/11/solved-xmlpullparse-error-problem-while.html

How can we know the input/output type of wcf service?

I am new to WCF and I wrote some service in wcf. It is now published on the Intranet and some applications are already using that service. At the moment, I have to make the documentation about the input parameters / data type and output parameters for other developers. It is ok, if we use .Net platform to consume the service. It automatically creates the services/classes in the WebReferences folder and Intellisense work perfectly.
But if the user is using PHP or classic ASP, it doesn't work that way. They have to know exact name, type of the parameters and I have to document the services very carefully.
By using WSDL as below: how can we know the datatype and parameters of the service we want to use? If it doesn't show in WSDL, where should I look at these information? If someone gave me WCF service without documentation, how could I know how to use that service?
Thanks very much.
This following is my Interface about the Service
[ServiceContract]
public interface IEmail
{
[OperationContract]
bool InsertEmail(string Subject, string SentFrom, string SentTo, int ApplicationID, int TemplateID, string DataText);
}
The following is the exact WSDL info about my service.
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions name="Email" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
- <wsdl:types>
- <xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://myservice/Email.svc?xsd=xsd0" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="http://myservice/Email.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
</xsd:schema>
</wsdl:types>
- <wsdl:message name="IEmail_InsertEmail_InputMessage">
<wsdl:part name="parameters" element="tns:InsertEmail" />
</wsdl:message>
- <wsdl:message name="IEmail_InsertEmail_OutputMessage">
<wsdl:part name="parameters" element="tns:InsertEmailResponse" />
</wsdl:message>
- <wsdl:portType name="IEmail">
- <wsdl:operation name="InsertEmail">
<wsdl:input wsaw:Action="http://tempuri.org/IEmail/InsertEmail" message="tns:IEmail_InsertEmail_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/IEmail/InsertEmailResponse" message="tns:IEmail_InsertEmail_OutputMessage" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="BasicHttpBinding_IEmail" type="tns:IEmail">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="InsertEmail">
<soap:operation soapAction="http://tempuri.org/IEmail/InsertEmail" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="Email">
- <wsdl:port name="BasicHttpBinding_IEmail" binding="tns:BasicHttpBinding_IEmail">
<soap:address location="http://myservice/Email.svc" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
If you mean that you can't see all the types your service uses in the WSDL, this is because the WSDL WCF creates is often (maybe always) split into several bits. These other bits are linked to from the main WSDL.
So if you browse to http://myservice/Email.svc?wsdl, you'll see the WSDL you've put in your question. In here, you can see links to two other schemas - http://myservice/Email.svc?xsd=xsd0 and http://myservice/Email.svc?xsd=xsd1. If you browse to these, you'll find the type information you're looking for.

Calling PHP webservice from .Net

I have created a Webservice in PHP and I'm trying to call it from my C# code.
When I try to create a proxy using wsdl utility
wsdl http://localhost:5365/DemoService.php?wsdl
I get this errors
Error: Cannot find definition for http://myserver.co.za/sayHello:sayHelloPortType.
Service Description with namespace http://myserver.co.za/sayHello is missing.
Parameter name: name
Here's my Webservice code (DemoService.php)
<?php
function sayHello($name){
$salutation = "Hi $name !";
return $salutation;
}
$server = new SoapServer("greetings.wsdl");
$server->addFunction("sayHello");
$server->handle();
?>
and my WSDL code (greetings.wsdl)
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='greetings'
targetNamespace='http://myserver.co.za/sayHello'
xmlns:tns=' http://myserver.co.za/sayHello'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='sayHelloRequest'>
<part name='name' type='xsd:string'/>
</message>
<message name='sayHelloResponse'>
<part name='salutation' type='xsd:string'/>
</message>
<portType name='sayHelloPortType'>
<operation name='sayHello'>
<input message='tns:sayHelloRequest'/>
<output message='tns:sayHelloResponse'/>
</operation>
</portType>
<binding name='sayHelloBinding' type='tns:sayHelloPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='sayHello'>
<soap:operation soapAction=''/>
<input>
<soap:body use='encoded' namespace=''
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace=''
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<documentation>This is Wiley's SOAP server Example</documentation>
<service name='sayHelloService'>
<port name='sayHelloPort' binding='sayHelloBinding'>
<soap:address location='http://localhost:5365/DemoService.php'/>
</port>
</service>
</definitions>
I really don't understand what it is trying to say. Can some one point me in a right direction?
Here is what is wrong with the WSDL
First the xmlns:tns namespace has a space at the start of it
xmlns:tns=' http://myserver.co.za/sayHello' <-- Bad
xmlns:tns='http://myserver.co.za/sayHello' <-- Good
Next the <documentation> node is in the wrong place, it should be inside the <service> node like so
<service ...>
<documentation>This is Wiley's SOAP server Example</documentation>
<port ...>
...
</port>
</service>
Your port binding element needs to use the tns namespace
<port name='sayHelloPort' binding='sayHelloBinding'> <-- Bad
<port name='sayHelloPort' binding='tns:sayHelloBinding'> <-- Good
Finally I could not get the soap:body to import as encoded, and had to swap them to literal, also note they need a value in the namespace element
<soap:body use='literal' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
I believe the soapAction element in the <soap:operation soapAction=''/> node still needs a value to work correctly, something like urn:xmethods-delayed-quotes#sayHello, but it will import without it.
Full WSDL (I caan import this using WSDL.exe without error)
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='greetings'
targetNamespace='http://myserver.co.za/sayHello'
xmlns:tns='http://myserver.co.za/sayHello'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='sayHelloRequest'>
<part name='name1' type='xsd:string'/>
</message>
<message name='sayHelloResponse'>
<part name='salutation' type='xsd:string'/>
</message>
<portType name='sayHelloPortType'>
<operation name='sayHello'>
<input message='tns:sayHelloRequest'/>
<output message='tns:sayHelloResponse'/>
</operation>
</portType>
<binding name='sayHelloBinding' type='tns:sayHelloPortType'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='sayHello'>
<soap:operation soapAction=''/>
<input>
<soap:body use='literal' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='literal' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='sayHelloService'>
<documentation>Service Description</documentation>
<port name='sayHelloPort' binding='tns:sayHelloBinding'>
<soap:address location='http://localhost:5365/DemoService.php'/>
</port>
</service>
</definitions>
Why don't you add the reference to the web service through:
right-click on project file -> add web reference --> type in the url to the webservice and voila!
This should create the necessary entries in Web.config (or App.config) plus the proxy classes that you'll use in your app.

Cannot consume WSDL in VS2010

I am trying to consume the following WSDL in VS2010 and Im running into errors which seem to be specific to the WSDL.
I am adding it as a Web Service Reference, and initially no proxy classes or anything are created - the wizard completes successfully and I get a .wsdl and a Reference.map file under ~/Web References/ in the project, however the service is unavailable in code.
If I do an "Update Web Reference" on it, I get the following error:
Custom tool error: Unable to import WebService/Schema. The element attribute is not allowed on encoded message parts. The erroneous part is named 'textReturnObject' in message 'singleTextResponse'. (File: Reference.map line 1 column 1)
If I try and rename "element" to "type" i get a whole bunch of other issues:
The custom tool 'MSDiscoCodeGenerator' failed. Cannot find definition for http://schemas.xmlsoap.org/wsdl/:exampleServiceNameBinding. Service Description with namespace http://schemas.xmlsoap.org/wsdl/ is missing.
Parameter name: name
Can anyone shed any light on it? I've put the WSDL through some online tools and they consume it fine - does VS2010 have an issue with certain types of WSDL?
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com/exampleServiceName" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="exampleServiceName" targetNamespace="http://www.example.com/exampleServiceName" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<xsd:complexType name="exampleType">
<sequence>
<element minOccurs="1" maxOccurs="1" name="title" type="string" />
<element minOccurs="1" maxOccurs="1" name="url" type="string" />
<element minOccurs="1" maxOccurs="1" name="description" type="string" />
</sequence>
</xsd:complexType>
<wsdl:types />
<wsdl:message name="singleTextRequest">
<wsdl:part name="intIdentity" type="xsd:integer" />
</wsdl:message>
<wsdl:message name="singleTextResponse">
<wsdl:part name="textReturnObject" element="wsdl:exampleType" />
</wsdl:message>
<wsdl:portType name="exampleServiceNamePortType">
<wsdl:operation name="singleTextAdvert">
<wsdl:input message="tns:singleTextRequest" />
<wsdl:output message="tns:singleTextResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="exampleServiceNameBinding" type="tns:exampleServiceNamePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
<wsdl:operation name="singleText">
<soap:operation soapAction="urn:xmethods-delayed-quotes#singleText" />
<wsdl:input>
<soap:body use="encoded" namespace="urn:xmethods-delayed-quotes" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="urn:xmethods-delayed-quotes" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="exampleServiceNameService">
<wsdl:port name="exampleServiceNamePort" binding="wsdl:exampleServiceNameBinding">
<soap:address location="http://www.example.com/exampleServiceName/Server.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I have a question on SO where I had trouble adding a service reference. I ended up using svcutil as recommended and it solved the problem. My situation was slightly different, but it's worth a try.
.net web service: Can't add service reference, only web reference
Yes, VS2010 can't create a web service reference from some WSDLs. Have to write custom wrapper for those. OR edit your WSDL in a way so VS can consume it. For example it may be ok for you to remove web service method references for the methods that you are not planning to use if those references create trouble for you.

VS 2008 wsdl tool converting xsd:positiveInteger to string

I have a web service written in C++ using gSoap. One of the methods of the webservice is
int HS__TBusinessComponentGetContents( xsd__positiveInteger pSession,
xsd__positiveInteger pComponentType,
xsd__string pPath,
xsd__string pFilter,
xsd__string pChangedAfter,
xsd__positiveInteger pFlags,
xsd__string &rResult);
Using these typedefs:
typedef double xsd__double;
typedef wchar_t *xsd__string;
typedef bool xsd__boolean;
typedef int xsd__int;
typedef unsigned long long xsd__positiveInteger;
typedef wchar_t *xsd__datetime;
I generate a wsdl file using this definition which has this (correct) part:
However, when I generate a Proxy class using the Visual Studio 2008 wsdl.exe tool to create a class which I can use from C#, the definition of the above methods is as follows:
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:tango04-hydra-server", ResponseNamespace="urn:tango04-hydra-server")]
[return: System.Xml.Serialization.SoapElementAttribute("rResult")]
public string TBusinessComponentGetContents([System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pSession, [System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pComponentType, string pPath, string pFilter, string pChangedAfter, [System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pFlags) {
object[] results = this.Invoke("TBusinessComponentGetContents", new object[] {
pSession,
pComponentType,
pPath,
pFilter,
pChangedAfter,
pFlags});
return ((string)(results[0]));
}
The WSDL is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="Publisher"
targetNamespace="http://127.0.0.1:18084/Publisher.wsdl"
xmlns:tns="http://127.0.0.1:18084/Publisher.wsdl"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:HS="urn:tango04-hydra-server"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:tango04-hydra-server"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:HS="urn:tango04-hydra-server"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>
</types>
<message name="SessionOpenRequest">
<part name="vCredentials" type="xsd:string"/>
</message>
<message name="SessionOpenResponse">
<part name="rResult" type="xsd:positiveInteger"/>
</message>
<message name="SessionCloseRequest">
<part name="rSession" type="xsd:positiveInteger"/>
</message>
<message name="SessionCloseResponse">
<part name="rResult" type="xsd:boolean"/>
</message>
<message name="SoapTestRequest">
</message>
<message name="SoapTestResponse">
<part name="rResult" type="xsd:boolean"/>
</message>
<message name="TBusinessComponentGetContentsRequest">
<part name="pSession" type="xsd:positiveInteger"/>
<part name="pComponentType" type="xsd:positiveInteger"/>
<part name="pPath" type="xsd:string"/>
<part name="pFilter" type="xsd:string"/>
<part name="pChangedAfter" type="xsd:string"/>
<part name="pFlags" type="xsd:positiveInteger"/>
</message>
<message name="TBusinessComponentGetContentsResponse">
<part name="rResult" type="xsd:string"/>
</message>
<portType name="PublisherPortType">
<operation name="SessionOpen">
<documentation>Service definition of function HS__SessionOpen</documentation>
<input message="tns:SessionOpenRequest"/>
<output message="tns:SessionOpenResponse"/>
</operation>
<operation name="SessionClose">
<documentation>Service definition of function HS__SessionClose</documentation>
<input message="tns:SessionCloseRequest"/>
<output message="tns:SessionCloseResponse"/>
</operation>
<operation name="SoapTest">
<documentation>Service definition of function HS__SoapTest</documentation>
<input message="tns:SoapTestRequest"/>
<output message="tns:SoapTestResponse"/>
</operation>
<operation name="TBusinessComponentGetContents">
<documentation>Service definition of function HS__TBusinessComponentGetContents</documentation>
<input message="tns:TBusinessComponentGetContentsRequest"/>
<output message="tns:TBusinessComponentGetContentsResponse"/>
</operation>
</portType>
<binding name="Publisher" type="tns:PublisherPortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="SessionOpen">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="SessionClose">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="SoapTest">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="TBusinessComponentGetContents">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="Publisher">
<documentation>Tango/04 Computing Group - Publisher </documentation>
<port name="Publisher" binding="tns:Publisher">
<SOAP:address location="http://127.0.0.1:18084"/>
</port>
</service>
</definitions>
My question is: why is this happening? Shouldn't the parameters be integers, or long long values instead of strings for the parameters that in the wsdl are marked as xsd:positiveInteger? What am I doing wrong here?
Thanks!
This may not be what you want to see but this may help: Microsoft
Basically what it gives you are the .Net datatypes that are associated with each xsd datatype. On that page it shows positiveInteger as a string. So, long story short it's doing what it's supposed to do. If you really want a number data type you may want to maybe look into using a Unsigned data type instead of positive integer, if you need it to always be positive. Otherwise just use an appropriate xsd datatype that will work for you. Since it looks like you have control over the web service and wsdl in c++ this should not be too difficult. If this is not something you want to do you will probably need to add logic checks on your c# client to make sure you are sending a number. Since everything technically goes over the wire as an xml string it technically doesn't matter as long as the service can serialize your request properly. Thus having data checks on your consumer object.
On a side note, when I have needed to develop services in the past we have always handcoded the xsd / wsdl contracts instead of letting tools generate them so we always know exactly what we will get. Not sure if that is what you have done but you could do that as well. When we do this we use the wsdl tool to generate the server proxy and the client proxy so you could generate the server side in cpp and the client in cs and then just fill in the guts the way you need it.
Hopefully that helps you out.

Categories