Setting Client Credentials in VSTO - c#

I'm trying to implement authentication using VSTO. I've added a web service reference which points to the WSDL below and it's generated all the classes necessary, however I can't find a class for the authentication, even though this is specified in the WSDL. I've tried editing the app.config file to make:
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
however, I still can't seem to get VS to generate the authentication classes which it should have auto-generated. Am I going about this the right way? Another option I searched was to create a SOAP extension. As all that really needs to happen is for the header to contain this authentication information:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
<wsu:Expires>2014-01-06T15:05:10.334Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>MyUserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPassword</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MyNonce==</wsse:Nonce>
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
WSDL:
<?xml version="1.0" encoding="utf-8"?>
<s0:definitions xmlns:s1="http://rsm.govt.nz/smart/download" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" name="DownloadService" targetNamespace="http://rsm.govt.nz/smart/download" xmlns:s0="http://schemas.xmlsoap.org/wsdl/">
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UTOverTransport">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Lax />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
</wsp:Policy>
</sp:SignedSupportingTokens>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<s0:types>
<xs:schema xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://rsm.govt.nz/smart/download" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://rsm.govt.nz/smart/download" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="DownloadLicences?xsd=LicenceDownloadService.xsd" />
</xs:schema>
</s0:types>
<s0:message name="LicenceDownloadException">
<s0:part name="errorMessage" element="s1:errorMessage" />
</s0:message>
<s0:message name="msgDetailResponse">
<s0:part name="detailResponse" element="s1:Licence" />
</s0:message>
<s0:message name="msgSearchResponse">
<s0:part name="searchResponse" element="s1:SearchResult" />
</s0:message>
<s0:message name="msgSearch">
<s0:part name="arg0" element="s1:SearchCriteria" />
</s0:message>
<s0:message name="msgDetail">
<s0:part name="arg0" element="s1:LicenceDetailsRequest" />
</s0:message>
<s0:portType name="LicenceDownloadWebService">
<s0:operation name="searchLicences">
<s0:input message="s1:msgSearch" />
<s0:output message="s1:msgSearchResponse" />
<s0:fault name="licenceDownloadException" message="s1:LicenceDownloadException" />
</s0:operation>
<s0:operation name="getLicenceDetails">
<s0:input message="s1:msgDetail" />
<s0:output message="s1:msgDetailResponse" />
<s0:fault name="licenceDownloadException" message="s1:LicenceDownloadException" />
</s0:operation>
</s0:portType>
<s0:binding name="LicenceDownloadServiceBinding" type="s1:LicenceDownloadWebService">
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
<s0:operation name="searchLicences">
<s2:operation soapAction="searchLicences" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
</s0:binding>
<s0:service name="LicenceDownloadService">
<s0:port name="LicenceDownloadServicePort" binding="s1:LicenceDownloadServiceBinding">
<s2:address location="https://data.eat.business.govt.nz/services/DownloadLicences" />
</s0:port>
</s0:service>
</s0:definitions>
Any help would be greatly appreciated.
Cheers!
I'll have a talk to the WSDL provider. I expected all the authentication information was included in the WSDL already from what I could see from:
<?xml version="1.0" encoding="utf-8"?>
<s0:definitions xmlns:s1="http://rsm.govt.nz/smart/download" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" name="DownloadService" targetNamespace="http://rsm.govt.nz/smart/download" xmlns:s0="http://schemas.xmlsoap.org/wsdl/">
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UTOverTransport">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Lax />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
</wsp:Policy>
</sp:SignedSupportingTokens>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<s0:types>
I can also be sure that there is a header in each SOAP request as using SOAP UI the SOAP message raw looks like this:
POST https://data.eat.business.govt.nz/services/DownloadLicences?wsdl HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "searchLicences"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: data.eat.business.govt.nz
Content-Length: 1219
<soapenv:Envelope xmlns:dow="http://rsm.govt.nz/smart/download" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
<wsu:Expires>2014-01-06T15:05:10.334Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>MyUserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPassword</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MyNonce==</wsse:Nonce>
<wsu:Created>2014-01-05T22:25:10.334Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<dow:SearchCriteria clientId="506682">
</dow:SearchCriteria>
</soapenv:Body>
</soapenv:Envelope>
Kind Regards
Evan

<s0:binding name="LicenceDownloadServiceBinding" type="s1:LicenceDownloadWebService">
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
<s0:operation name="searchLicences">
<s2:operation soapAction="searchLicences" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
Above is your wsdl bindings, I am not able to see any operation here, responsible for authentication. That's why it's not generating your required class, i guess.
Ask your wsdl provider to implement authentication method which is required by you and regenerate wsdl..
Updated:
The authentication information e.g. username, password etc. are all included within the header of each SOAP method. Which means when I send a "searchLicences" or "getLicenceDetails" message it will include the authentication details within the header of those messages
How are you so sure about header of soap message because as per your wsdl there is no soap header will come in your request.
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
If there would be a header in your incoming soap request it would be something like this.
<s2:binding transport="http://schemas.xmlsoap.org/soap/http" />
<s0:operation name="getLicenceDetails">
<s2:operation soapAction="getLicenceDetails" style="document" />
<s0:input>
<s2:body use="literal" />
<s2:header message="tns:getAuthHeader" part="username" use="literal" />
<s2:header message="tns:getAuthHeader" part="password" use="literal" />
</s0:input>
<s0:output>
<s2:body use="literal" />
</s0:output>
<s0:fault name="licenceDownloadException">
<s2:fault use="literal" name="licenceDownloadException" namespace="" />
</s0:fault>
</s0:operation>
There is one more thing, sometimes webservice provider hide few methods like authentication in wsdl. You should consult your wsdl provider to include that method in your wsdl. Otherwise you won't able to generate that class in your client.

Related

WCF client receiving response with null value even though response has data

I'm using WCF client in this very simple way:
using (var client = new ExampleService_TestClient())
{
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "pass";
var request = new ExampleService_TestRequest(requestData);
var response = client.ExampleService_Test(request);
// response.Response_MT is null
// when it should have errorMsg="OK"
}
The data is sent correctly.
However the response property errorMsg is null.
Here is the envelope:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Inbound_MT xmlns="https://example.com/ExampeService/">
<event_id xmlns="">1</event_id>
<event_name xmlns="">insert</event_name>
<event_date xmlns="">2017-06-22 16:09</event_date>
<employee_number xmlns="">666</employee_number>
<employee_first_name xmlns="">Chuck</employee_first_name>
<employee_last_name xmlns="">Inserted Norris</employee_last_name>
</Inbound_MT>
</s:Body>
</s:Envelope>
The response I see using fiddler:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header></soap:Header><soap:Body><Response_MT>
<errorMsg>OK</errorMsg>
</Response_MT></soap:Body>
</soap:Envelope>
WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:p1="https://example.com/ExampeService/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" targetNamespace="https://example.com/ExampeService/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://example.com/ExampeService/" targetNamespace="https://example.com/ExampeService/">
<xsd:element name="Inbound_MT" type="Inbound_DT" />
<xsd:element name="Response_MT" type="Response_DT" />
<xsd:complexType name="Inbound_DT">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="event_id" type="xsd:integer" />
<xsd:element maxOccurs="1" minOccurs="1" name="event_name" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="1" name="event_date" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="1" name="employee_number" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="employee_first_name" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="employee_last_name" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Response_DT">
<xsd:sequence>
<xsd:element name="errorMsg" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="Inbound_MT">
<wsdl:documentation />
<wsdl:part element="p1:Inbound_MT" name="Inbound_MT" />
</wsdl:message>
<wsdl:message name="Response_MT">
<wsdl:documentation />
<wsdl:part element="p1:Response_MT" name="Response_MT" />
</wsdl:message>
<wsdl:portType name="ExampleService_Test">
<wsdl:documentation />
<wsdl:operation name="ExampleService_Test">
<wsdl:documentation />
<wsdl:input message="p1:Inbound_MT" />
<wsdl:output message="p1:Response_MT" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ExampleService_TestBinding" type="p1:ExampleService_Test">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsp:Policy>
<wsp:PolicyReference URI="#BN__binding" />
</wsp:Policy>
<wsdl:operation name="ExampleService_Test">
<soap:operation soapAction="https://example.com/ExampeService//ExampleService_Test" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SOME_GREAT_SERVICE">
<wsdl:documentation>WS_GS</wsdl:documentation>
<wsdl:port binding="p1:ExampleService_TestBinding" name="ExampleService_Test">
<soap:address location="https://endpointaddress/cxf/ExampleService_Test" />
</wsdl:port>
</wsdl:service>
<wsp:UsingPolicy required="true" />
<wsp:Policy wsu:Id="BN__binding">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken>
<wsp:Policy>
<wsp:ExactlyOne>
<sp:HttpBasicAuthentication />
<sp:RequireClientCertificate />
</wsp:ExactlyOne>
</wsp:Policy>
</sp:HttpsToken>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<wsp:ExactlyOne>
<sp:Basic256 />
<sp:Basic192 />
<sp:Basic128 />
<sp:TripleDes />
<sp:Basic256Rsa15 />
<sp:Basic192Rsa15 />
<sp:Basic128Rsa15 />
<sp:TripleDesRsa15 />
<sp:Basic256Sha256 />
<sp:Basic192Sha256 />
<sp:Basic128Sha256 />
<sp:TripleDesSha256 />
<sp:Basic256Sha256Rsa15 />
<sp:Basic192Sha256Rsa15 />
<sp:Basic128Sha256Rsa15 />
<sp:TripleDesSha256Rsa15 />
</wsp:ExactlyOne>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</wsdl:definitions>
Based on your wsdl it looks like your return is XML and not an object (I didn't see a data contract). Since the response is XML, you cannot refer directly to the response variable with dot-notation. You need to first parse the response into an object you can understand and inspect.
Have you set a break-point on var response to see if it is a string containing the XML?
You can do something like this and immediately access nodes of the response using xpath:
var response = new XmlDocument();
response.LoadXml(client.ExampleService_Test(request));
var errorMsg = response.SelectSingleNode("//Response_MT/errorMsg");

Convert WSE3 Web Service Client Code to WCF

Convert WSE3 Web Service Client Code to WCF
Hi. It would be much appreciated if an expert could be able to convert the following WSE3 web service client code to some working(well as much as possible) WCF code(preferable with configuration in code and entire code as short as can be) please? I've seen some examples using the ChannelFactory class but there may be a cleaner/shorter way.
The 3rd Party web service being called is: HTTPS, EndPoint is ASMX file, SOAP 1.1, and using ws-security. The working WSE3 code is:
Dim ExpCertificate As New X509Certificate2
ExpCertificate = New X509Certificate2("<pfx file>", "<password>")
Dim waspservice As New TokenService
waspservice.ClientCertificates.Add(ExpCertificate)
waspservice.Url = "https://somesite.asmx"
Dim res As String = waspservice.STS("<WASPAuthenticationRequest><ApplicationName>Example Client</ApplicationName><AuthenticationLevel>CertificateAuthentication</AuthenticationLevel><AuthenticationParameters/></WASPAuthenticationRequest>")
Response.Write(res & vbCrLf & vbCrLf)
An example soap request is:
<wsse:Security>
<wsu:Timestampwsu:Id="Timestamp-2b27a32b-ca9c-4405-b377-4444f63c8f29">
<wsu:Created>2011-02-20T16:36:54Z</wsu:Created>
<wsu:Expires>2011-02-20T16:41:54Z</wsu:Expires>
</wsu:Timestamp>
<wsse:BinarySecurityToken ValueType="CompanyWASP" EncodingType="wsse:Base64Binary" wsu:Id="SecurityToken-f64439f9-c12c-4d09-ac3d-fc478ad19775">MjAtRTctQ0YtMTUtN0EtODEtNTk.</wsse:BinarySecurityToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<! -- SOAP content for the service call -- >
</soap:Body>
The WSDL is:
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.uk.company.com/WASP/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://www.uk.company.com/WASP/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.uk.company.com/WASP/">
<s:element name="STS">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="authenticationBlock" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="STSResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="STSResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</wsdl:types>
<wsdl:message name="STSSoapIn">
<wsdl:part name="parameters" element="tns:STS" />
</wsdl:message>
<wsdl:message name="STSSoapOut">
<wsdl:part name="parameters" element="tns:STSResponse" />
</wsdl:message>
<wsdl:message name="STSHttpGetIn">
<wsdl:part name="authenticationBlock" type="s:string" />
</wsdl:message>
<wsdl:message name="STSHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="STSHttpPostIn">
<wsdl:part name="authenticationBlock" type="s:string" />
</wsdl:message>
<wsdl:message name="STSHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:portType name="TokenServiceSoap">
<wsdl:operation name="STS">
<wsdl:input message="tns:STSSoapIn" />
<wsdl:output message="tns:STSSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TokenServiceHttpGet">
<wsdl:operation name="STS">
<wsdl:input message="tns:STSHttpGetIn" />
<wsdl:output message="tns:STSHttpGetOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TokenServiceHttpPost">
<wsdl:operation name="STS">
<wsdl:input message="tns:STSHttpPostIn" />
<wsdl:output message="tns:STSHttpPostOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TokenServiceSoap" type="tns:TokenServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="STS">
<soap:operation soapAction="http://www.uk.company.com/WASP/STS" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TokenServiceHttpGet" type="tns:TokenServiceHttpGet">
<http:binding verb="GET" />
<wsdl:operation name="STS">
<http:operation location="/STS" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TokenServiceHttpPost" type="tns:TokenServiceHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="STS">
<http:operation location="/STS" />
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TokenService">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">company Token Service</documentation>
<wsdl:port name="TokenServiceSoap" binding="tns:TokenServiceSoap">
<soap:address location="https://secure.authenticator.uat.uk.company.com/WaspAuthenticator/TokenService.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Generate proxy class either of using
wsdl.exe OR by adding service reference in visual studio. That will create required proxy.
Proxy will have methods which you want to call. Pass in required parameters and you should be good.

Error generating Proxy Class from WSDL document

Following is the WSDL file and I am unable to generate the Proxy class for this WSDL file.
<?xml version ='1.0' encoding ='ISO-8859-1' ?>
<definitions name='SunesisService' targetNamespace='https://exg.sunesis.uk.net/' xmlns:tns='https://exg.sunesis.uk.net/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<wsdl:types>
<xsd:schema targetNamespace="https://exg.sunesis.uk.net/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="destinyXML">
<xsd:complexType name="mimeXmlType" use="required">
<xsd:sequence>
<xsd:any/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<message name='receiveILRRequest'>
<part name='receiveILRRequest_username' type='xsd:string' />
<part name='receiveILRRequest_password' type='xsd:string' />
<part name='receiveILRRequest_destinyXMLFileName' type='xsd:string' />
<part name='receiveILRRequest_destinyXML' type='mimeXmlType' />
</message>
<message name='receiveILRResponse'>
<part name='receiveILRResponse_Result' type='xsd:string' />
</message>
<portType name='DestinyReceipt'>
<operation name='acceptEXG'>
<input message='tns:receiveILRRequest'/>
<output message='tns:receiveILRResponse'/>
</operation>
</portType>
<binding name='SunesisBinding' type='tns:DestinyReceipt'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
<operation name='acceptEXG'>
<soap:operation soapAction='urn:localhost-catalog#acceptILR'/>
<input>
<soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
</input>
<output>
<soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
</output>
</operation>
</binding>
<service name='SunesisService'>
<port name='SunesisPort' binding='SunesisBinding'>
<soap:address location='https://exg.sunesis.uk.net/module_soap/sunesis.php' />
</port>
</service>
You must close your definitions node in the end of your document
try with this format
<definitions name='SunesisService' targetNamespace='https://exg.sunesis.uk.net/' xmlns:tns='https://exg.sunesis.uk.net/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
..........
<service name='SunesisService'>
<port name='SunesisPort' binding='SunesisBinding'>
<soap:address location='https://exg.sunesis.uk.net/module_soap/sunesis.php' />
</port>
</service>
</definitions>

ClientBase classes are not available in Reference.cs file

I added a service reference in Visual Studio 2010 using following wsdl. It is added successfully. This is a wsdl generated from schema xsd files; not from actual service code. Any idea why this is not generating the required class and methods in Reference.cs file?
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:import0="urn:thinktecture-com:demos:restaurantservice:messages:v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import1="urn:thinktecture-com:demos:restaurantservice:data:v1" xmlns:tns="urn:lijo:demos:multiplyservice:calculation:v1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="CalculationService" targetNamespace="urn:lijo:demos:multiplyservice:calculation:v1" xmlns="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<types>
<xsd:schema>
<xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantMessages.xsd" namespace="urn:thinktecture-com:demos:restaurantservice:messages:v1" />
<xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantData.xsd" namespace="urn:thinktecture-com:demos:restaurantservice:data:v1" />
</xsd:schema>
</types>
<message name="getMultipliedIn">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<part name="parameters" element="import0:getMultiplied" />
</message>
<message name="getMultipliedOut">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<part name="parameters" element="import0:getMultipliedResponse" />
</message>
<portType name="CalculationServiceInterface">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<operation name="getMultiplied">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<input message="tns:getMultipliedIn" />
<output message="tns:getMultipliedOut" />
</operation>
</portType>
<binding name="BasicHttpBinding_CalculationServiceInterface" type="tns:CalculationServiceInterface">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getMultiplied">
<soap:operation soapAction="urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn" style="document" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="CalculationServicePort">
<port name="CalculationServicePort" binding="tns:BasicHttpBinding_CalculationServiceInterface">
<soap:address location="http://localhost/CalculationService" />
</port>
</service>
</definitions>
The issue was with incorrect xml namespace used by the tool. Please see the corrected wsdl in 400 Bad Request Exception: Simple SOAP WCF service with small data

Warning: The optional WSDL extension element 'body' from namespace 'http://schemas.xmlsoap.org/wsdl/soap/' was not handled

I'm using Visual Studio 2010, .Net4, Silverlight(4.0.50826.0).
I created a WCF service and I`m trying to create a proxy with SlSvcUtil like:
SlSvcUtil.exe /serializer:DataContractSerializer http://192.128.09.26:8080/Server?wsdl /out:C:\Projets\Client\dService.cs /config:C:\Projets\Client\ServiceReferences.ClientConfig
When I add some methods with customer type and also they have some attributes I got this msg:
Warning: The optional WSDL extension element 'body' from namespace
'http://schemas.xmlsoap.org/wsdl/soap/' was not handled.
XPath:
//wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#
name='BasicHttpBinding_IService']/wsdl:operation[#name='GetDefinitionsHavingFre']/wsdl:output
If I ignore the warning and I try to use the class I get a NullException error when I call any method.
If I change the option /Serializer:XmlSerializer or any other option Its possible create the proxy correctly but I get a lot of null references in the visual studio, so Its necessary to add the correct .dll.
If I add: System.ServiceModel from Silverlight -the xmlserializerformatattribute doesn't exist System.ServiceModel from .NET -the ChannelBase doesn't exist
If I didn't use the customer method my service works fine, so my question is has silverlight some limit when use customer types or methods with attributes ?
Someone has some clue what could be done to solve this ?
Thanks,
WSDL:
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions name="TestService" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 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:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex">
- <wsdl:types>
- <xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd0" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd10" namespace="http://schemas.datacontract.org/2004/07/DataCompany.Data.Faults" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/DataCompany.Data.PortalModel" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd4" namespace="http://schemas.datacontract.org/2004/07/System.Data" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd5" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd6" namespace="http://schemas.datacontract.org/2004/07/DataCompany.Data.Components" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd7" namespace="http://schemas.datacontract.org/2004/07/System" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd8" namespace="http://schemas.datacontract.org/2004/07/DataCompany.Data" />
<xsd:import schemaLocation="http://192.128.09.26:8080/Server?xsd=xsd9" namespace="http://schemas.datacontract.org/2004/07/DataCompany.Data.LocalizationManagement" />
</xsd:schema>
</wsdl:types>
- <wsdl:message name="ITestService_StatusService_InputMessage">
<wsdl:part name="parameters" element="tns:StatusService" />
</wsdl:message>
- <wsdl:message name="ITestService_StatusService_OutputMessage">
<wsdl:part name="parameters" element="tns:StatusServiceResponse" />
</wsdl:message>
- <wsdl:message name="ITestService_getData_InputMessage">
<wsdl:part name="parameters" element="tns:getData" />
</wsdl:message>
- <wsdl:message name="ITestService_getData_OutputMessage">
<wsdl:part name="parameters" element="tns:getDataResponse" />
</wsdl:message>
- <wsdl:message name="ITestService_getTime_InputMessage">
<wsdl:part name="parameters" element="tns:getTime" />
</wsdl:message>
- <wsdl:message name="ITestService_getTime_OutputMessage">
<wsdl:part name="parameters" element="tns:getTimeResponse" />
</wsdl:message>
- <wsdl:message name="ITestService_getText_InputMessage">
<wsdl:part name="parameters" element="tns:getText" />
</wsdl:message>
- <wsdl:message name="ITestService_getText_OutputMessage">
<wsdl:part name="parameters" element="tns:getTextResponse" />
</wsdl:message>
- <wsdl:message name="ITestService_SaveEntity_InputMessage">
<wsdl:part name="parameters" element="tns:SaveEntity" />
</wsdl:message>
- <wsdl:message name="ITestService_SaveEntity_OutputMessage">
<wsdl:part name="parameters" element="tns:SaveEntityResponse" />
</wsdl:message>
- <wsdl:message name="ITestService_SaveEntity_DatabaseFaultFault_FaultMessage">
<wsdl:part name="detail" element="q1:DatabaseFault" xmlns:q1="http://schemas.datacontract.org/2004/07/DataCompany.Data.Faults" />
</wsdl:message>
- <wsdl:portType name="ITestService">
- <wsdl:operation name="StatusService">
<wsdl:input wsaw:Action="http://tempuri.org/ITestService/StatusService" message="tns:ITestService_StatusService_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ITestService/StatusServiceResponse" message="tns:ITestService_StatusService_OutputMessage" />
</wsdl:operation>
- <wsdl:operation name="getData">
<wsdl:input wsaw:Action="http://tempuri.org/ITestService/getData" message="tns:ITestService_getData_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ITestService/getDataResponse" message="tns:ITestService_getData_OutputMessage" />
</wsdl:operation>
- <wsdl:operation name="getTime">
<wsdl:input wsaw:Action="http://tempuri.org/ITestService/getTime" message="tns:ITestService_getTime_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ITestService/getTimeResponse" message="tns:ITestService_getTime_OutputMessage" />
</wsdl:operation>
- <wsdl:operation name="getText">
<wsdl:input wsaw:Action="http://tempuri.org/ITestService/getText" message="tns:ITestService_getText_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ITestService/getTextResponse" message="tns:ITestService_getText_OutputMessage" />
</wsdl:operation>
- <wsdl:operation name="SaveEntity">
<wsdl:input wsaw:Action="http://tempuri.org/ITestService/SaveEntity" message="tns:ITestService_SaveEntity_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ITestService/SaveEntityResponse" message="tns:ITestService_SaveEntity_OutputMessage" />
<wsdl:fault wsaw:Action="http://tempuri.org/ITestService/SaveEntityDatabaseFaultFault" name="DatabaseFaultFault" message="tns:ITestService_SaveEntity_DatabaseFaultFault_FaultMessage" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="BasicHttpBinding_ITestService" type="tns:ITestService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="StatusService">
<soap:operation soapAction="http://tempuri.org/ITestService/StatusService" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="getData">
<soap:operation soapAction="http://tempuri.org/ITestService/getData" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="getTime">
<soap:operation soapAction="http://tempuri.org/ITestService/getTime" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="getText">
<soap:operation soapAction="http://tempuri.org/ITestService/getText" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="SaveEntity">
<soap:operation soapAction="http://tempuri.org/ITestService/SaveEntity" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
- <wsdl:fault name="DatabaseFaultFault">
<soap:fault name="DatabaseFaultFault" use="literal" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="TestService">
- <wsdl:port name="BasicHttpBinding_ITestService" binding="tns:BasicHttpBinding_ITestService">
<soap:address location="http://192.128.09.26:8080/Server" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I Found the problem.
After creating the proxy with SlSvcUtil and adding the .cs in my project in Visual Studio I got this error:
The type or namespace name 'XmlSerializerFormatAttributeAttribute' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)
First of all I tried change the System.Service.Model from the Silverlight version to the .Net version, but I got other errors.
So I found somewhere that was necessary, use /serializer:DataContractSerializer in the SlSvcUtil; after that this error was solved. However I got a WSDL warning when the proxy is generated.
SOLUTION
I created the proxy using the following command:
SlSvcUtil.exe http://192.128.09.26:8080/Server /out:C:\Projets\Client\dService.cs /config:C:\Projets\Client\ServiceReferences.ClientConfig
Then the I got this error in Visual Studio:
The type or namespace name 'XmlSerializerFormatAttributeAttribute' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)
I added the following dll:
System.Xml.Serialization.dll - (Runtime Version v2.0.50727)
Conclusion
Visual Studio wasn't able to find the reference inside the ServiceModel.dll and the ServiceModel was there so I never thought to add another .dll because the correct dll was already added.
Just yesterday I tried add the System.Xml.Serialization.dll and now everthing works fine.

Categories

Resources