I am using Visual studio 2008 C# Windows application to connect to a webservice created by an external company. The service is a WSDL url, which is a basic soap request and response. I have inported the service as a service reference. I can call the service, and receive no errors, but the reponse is nothing. When monitoring the soap request and response in Fiddler, i see a response coming back, but it's as if VS cannot interpret the response. I have looked at creating xsd's, but get an error stating that there's already a schema. So I am at a total loss. I hope someone can help. I apologise if this exact issue has been solved before, but i cannot find anything that resolves my problem.
Thanks in advance!
The code I am using to connect to the service is as follows:
ServiceReference1.bpm bbb = new TestingWSDL.ServiceReference1.bpm();
ServiceReference1.BPMExternalAppServicesV001Client soapClient = new TestingWSDL.ServiceReference1.BPMExternalAppServicesV001Client();
ServiceReference1.DownloadShipmentDataV001 req = new TestingWSDL.ServiceReference1.DownloadShipmentDataV001();
ServiceReference1.DownloadShipmentDataV001Response resp = new TestingWSDL.ServiceReference1.DownloadShipmentDataV001Response();
try
{
soapClient.DownloadShipmentDataV001(req,out resp);
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
the response object does not have any data in. I cannot post an image, as i am not allowed.
The WSDL is quite long and is as follows:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:tns="http://schemas.ccc.com/AROPInventory/bpm/external" xmlns:inst="http://schemas.aaa.com/bpm/instance/1.0" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="BPMExternalAppServicesV001" targetNamespace="http://schemas.ccc.com/AROPInventory/bpm/external" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns:tns1="http://schemas.ccc.com/AROPInventory/bpm/external" xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.argility.com/AROPInventory/bpm/external" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://schemas.aaa.com/bpm/instance/1.0" />
<xsd:element name="UploadShipmentDataV001">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns1:Shipments" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" name="Shipments">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="Shipment">
<xsd:complexType>
<xsd:sequence>
<xs:element name="ShipmentNumber" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
<xsd:element name="Cartons">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="Carton">
<xsd:annotation>
<xsd:documentation>0:not damaged 1:damaged 2: Rejected0:not damaged 1:damaged 2: Rejected0:not damaged 1:damaged 2: Rejected</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xs:element name="CartionID" type="xs:byte" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
<xs:element name="Status" type="xs:byte" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="TestUploadShipMentV001">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns1:Shipments" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="TestUploadShipMentV001Response" />
<xsd:element name="UploadShipmentDataV001Response" />
<xsd:element name="DownloadShipmentDataV001">
<xsd:complexType>
<xsd:sequence />
</xsd:complexType>
</xsd:element>
<xsd:element name="DownloadShipmentDataV001Response">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns1:Shipments" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.aaa.com/bpm/instance/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="bpm">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="instance_id" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="DownloadShipmentDataV001Input">
<wsdl:part name="body" element="tns:DownloadShipmentDataV001" />
</wsdl:message>
<wsdl:message name="DownloadShipmentDataV001Output">
<wsdl:part name="body" element="tns:DownloadShipmentDataV001Response" />
</wsdl:message>
<wsdl:message name="HeaderOutput">
<wsdl:part name="BPMHeader" element="inst:bpm" />
</wsdl:message>
<wsdl:portType name="BPMExternalAppServicesV001">
<wsdl:operation name="DownloadShipmentDataV001">
<wsdl:input message="tns:DownloadShipmentDataV001Input" />
<wsdl:output message="tns:DownloadShipmentDataV001Output" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BPMExternalAppServicesV001" type="tns:BPMExternalAppServicesV001">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="DownloadShipmentDataV001">
<soap:operation soapAction="" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
<soap:header message="tns:HeaderOutput" part="BPMHeader" use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BPMExternalAppServicesV001Service">
<wsdl:port name="BPMExternalAppServicesV001Port" binding="tns:BPMExternalAppServicesV001">
<soap:address location="http://aaa/aaa/com.eibus.web.soap.Gateway.wcp?organization=o=system,cn=aaa,cn=aaa,o=ho.bbb.co.za" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The fiddler response is as follows:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://schemas.aaa.com/General/1.0/">
<sender>
<reply-to>
cn=Business Process Management,cn=Business Process Management,cn=soap nodes,o=system,cn=aaa,cn=aaa20,o=ho.bbb.co.za
</reply-to>
<organizationalContext>o=system,cn=aaa,cn=aaa20,o=ho.bbb.co.za</organizationalContext>
<component>cn=Business Process Management,cn=soap nodes,o=system,cn=aaa,cn=aaa20,o=ho.bbb.co.za</component>
</sender>
<receiver>
<component>cn=webgateway#poc-aaa,cn=aaa,cn=aaa20,o=ho.bbb.co.za</component>
<sent-to xmlns="http://schemas.aaa.com/General/1.0/">socket://poc-aaa:20379/</sent-to>
</receiver>
<msg-id>00505680-004E-11E1-FBF1-7CB604BB1FC0</msg-id>
</header>
<bpm xmlns="http://schemas.aaa.com/bpm/instance/1.0">
<instance_id>26c34038-bea4-459c-a0ad-86b462ae90cb</instance_id>
</bpm>
</s:Header>
<s:Body>
<DownloadShipmentDataV001Response xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.argility.com/AROPInventory/bpm/external">
<Shipments xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.argility.com/AROPInventory/bpm/external">
<ShipmentHeader>
<ShipmentNumber>S001</ShipmentNumber>
<ReceivingBranch>B000028</ReceivingBranch>
<SendingBranch>B000001</SendingBranch>
<ExpectedDate>2012/07/30</ExpectedDate>
<TotalNrOfCartons>2</TotalNrOfCartons>
<ShipmentStatus>E</ShipmentStatus>
<Cartons>
<Carton>
<CartonHeader>
<NrOfItems>2</NrOfItems>
<CartionID>99</CartionID>
</CartonHeader>
<CartonDetail>
<SKU>12345</SKU>
<Description>abc</Description>
<SerialNumber>6789</SerialNumber>
<QtySent>20</QtySent>
<QtyReceived/>
</CartonDetail>
<CartonDetail>
<SKU>12390</SKU>
<Description>abc</Description>
<SerialNumber>67232</SerialNumber>
<QtySent>2</QtySent>
<QtyReceived/>
</CartonDetail>
</Carton>
<Carton>
<CartonHeader>
<NrOfItems>2</NrOfItems>
<CartionID>100</CartionID>
</CartonHeader>
<CartonDetail>
<SKU>12345</SKU>
<Description>abc</Description>
<SerialNumber>6789</SerialNumber>
<QtySent>20</QtySent>
<QtyReceived/>
</CartonDetail>
<CartonDetail>
<SKU>12390</SKU>
<Description>abc</Description>
<SerialNumber>67232</SerialNumber>
<QtySent>2</QtySent>
<QtyReceived/>
</CartonDetail>
</Carton>
</Cartons>
</ShipmentHeader>
<ShipmentHeader>
<ShipmentNumber>S002</ShipmentNumber>
<ReceivingBranch>B000029</ReceivingBranch>
<SendingBranch>B000002</SendingBranch>
<ExpectedDate>2012/06/3</ExpectedDate>
<TotalNrOfCartons>21</TotalNrOfCartons>
<ShipmentStatus>E</ShipmentStatus>
<Cartons>
<Carton>
<CartonHeader>
<NrOfItems>3</NrOfItems>
<CartionID>91</CartionID>
</CartonHeader>
<CartonDetail>
<SKU>12345</SKU>
<Description>abc</Description>
<SerialNumber>6789</SerialNumber>
<QtySent>20</QtySent>
<QtyReceived/>
</CartonDetail>
<CartonDetail>
<SKU>12390</SKU>
<Description>abc</Description>
<SerialNumber>67232</SerialNumber>
<QtySent>2</QtySent>
<QtyReceived/>
</CartonDetail>
</Carton>
<Carton>
<CartonHeader>
<NrOfItems>1</NrOfItems>
<CartionID>97</CartionID>
</CartonHeader>
<CartonDetail>
<SKU>12390</SKU>
<Description>abc</Description>
<SerialNumber>67232</SerialNumber>
<QtySent>2</QtySent>
<QtyReceived/>
</CartonDetail>
</Carton>
</Cartons>
</ShipmentHeader>
</Shipments>
</DownloadShipmentDataV001Response>
</s:Body>
</s:Envelope>
Thanks for posting the response as collected by Fiddler. I am actually seeing more than one problem in the WSDL and in the response conformance to the WSDL datatypes.
First issue: WSDL consistency/completeness
Note that the input and output messages refer to tns:DownloadShipmentDataV001 and tns:DownloadShipmentDataV001Response, respectively. xmlns:tns="http://schemas.ccc.com/AROPInventory/bpm/external" is the relevant prefix:namespace binding in the context of the message definitions, thus the fully-qualified names of the request and response message elements are {http://schemas.ccc.com/AROPInventory/bpm/external}DownloadShipmentDataV001 and {http://schemas.ccc.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response, respectively.
By virtue of the targetNamespace="http://schemas.argility.com/AROPInventory/bpm/external" declaration, the fully-qualified name of the elements defined in the types section of the WSDL document are
{http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001 and {http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response. This is a problem because the actual types referred to in the message definitions are missing from the WSDL and any imported/included documents.
A stub generator should complain about this when trying to consume the WSDL.
The external company should really correct this issue, but you could copy the WSDL and make a tweak by declaring the namespace of the actual element from the types section and binding to a prefix, then using that prefix in the message definition (weakness being you have an extra step in keeping up with any changes in their service definition):
xmlns:fromtype="http://schemas.argility.com/AROPInventory/bpm/external"
...
<wsdl:message name="DownloadShipmentDataV001Input">
<wsdl:part name="body" element="fromtype:DownloadShipmentDataV001" />
</wsdl:message>
<wsdl:message name="DownloadShipmentDataV001Output">
<wsdl:part name="body" element="fromtype:DownloadShipmentDataV001Response" />
</wsdl:message>
Second issue: Response Message Does Not Match Schema
Assume that the WSDL was consistent and called out the fully-qualified datatype from the types section. The response message's fully-qualified element structure would then be expected to be something like:
{http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response
{http://schemas.argility.com/AROPInventory/bpm/external}Shipments
{http://schemas.argility.com/AROPInventory/bpm/external}Shipment
{http://schemas.argility.com/AROPInventory/bpm/external}ShipmentNumber
{http://schemas.argility.com/AROPInventory/bpm/external}Cartons
{http://schemas.argility.com/AROPInventory/bpm/external}Carton
...
However, the actual structure in the response message is:
{http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response
{http://schemas.argility.com/AROPInventory/bpm/external}Shipments
{http://schemas.argility.com/AROPInventory/bpm/external}ShipmentHeader
{http://schemas.argility.com/AROPInventory/bpm/external}ShipmentNumber
...
Note that ShipmentHeader is never declared as an element in the WSDL types section and is not imported from another document. If the unmarshaller is using the datatype definition provided in the WSDL, it does not understand the ShipmentHeader or its subelements so probably would leave those out (as you are seeing).
The correction for this issue is to match up the datatype schema definition with the actual response from the service. Again, the external organization hosting the service should correct this (their service is not in compliance with the given WSDL), but you could again tweak locally with the same caveat about extra steps keeping 'your' wsdl in lock-step with their service.
I hope this helps and respond back with further questions.
You will still need to parse this XML file yourself.
We have a similar problem with IBM's Remedy software. Basically it is terrible software and this behavior should be expected. Even if they update the code to match they are not generating the WSDL from the actual XML document they are generating... this problem will continue until they change their methods and you have no control over that.
I had a similar problem with empty answer but in fiddler it said the opposite. I fixed it by removing the
`System.ServiceModel.XmlSerializerFormatAttribute attribute and was able to serialize the response. Not the optimal solution but it worked for me.
Related
i want to create WSDL URL in SAP Remote enabled function module which needs to be use for both request/response from 3rd party client.
i have followed this tutorial Consume and create a Web Service ABAP, SOAMANAGER Transaction
i got everything at the end ,
this is my WSDL URL http://host:port/sap/bc/srt/wsdl/flv_10002A111AD1/srvc_url/sap/bc/srt/rfc/sap/z_web_service_definition/199/z_web_service_name/z_web_binding?sap-client=199, which contains the exact XML data what i need,
the problem i am facing is when i try connect this url from my C#-Console application which hits Binding ULR http://host:port/sap/bc/srt/rfc/sap/z_web_service_definition/199/z_web_service_name/z_web_binding ,
when i check this URL in browser no XML is loading hence i am getting error in C# that
Web Exception as Client found response content type of 'text/xml; charset=utf-8', but expected 'text/xml'
z_web_service_name service = new z_web_service_name(); // SAP Web Service
ZmmBatchPutawayFromPhp data = new ZmmBatchPutawayFromPhp(); // SAP Funcion Module
data.PBktxt = "Text";
NetworkCredential cred = new NetworkCredential(); // Client credential
cred.UserName = "XXXXX";
cred.Password = "*****";
cred.Domain = "host";
service.Credentials = cred;
service.Proxy = new WebProxy("host", port);
service.Credentials = cred;
ZmmBatchPutawayFromPhpResponse response = new ZmmBatchPutawayFromPhpResponse();
response = service.ZmmBatchPutawayFromPhp(data); // connect to SAP
Console.Write(response.ToString());
anyone please help me to solve this or how exactly need to connect in C# application ?
z_web_service_name is a service which i created in SAP , ZmmBatchPutawayFromPhp is a function module which i created in function module , with the help of SOAMANAGER i have created WSDL file with help of service definition and binding.
example XML Code ,i cannot copy complete XML file since its too large.
<wsdl:service name="z_web_service_name">
<wsdl:port name="z_web_binding" binding="tns:z_web_binding">
<soap:address location="http://PORT:8000/sap/bc/srt/rfc/sap/z_web_service_definition/199/z_web_service_name/z_web_binding" />
</wsdl:port>
<wsdl:port name="z_web_binding_soap12" binding="tns:z_web_binding_soap12">
<wsoap12:address location="http://PORT:8000/sap/bc/srt/rfc/sap/z_web_service_definition/199/z_web_service_name/z_web_binding" />
</wsdl:port>
</wsdl:service>
zmmBatchPutawayFromPhp
<xsd:element name="ZmmBatchPutawayFromPhp">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="PBktxt" type="n0:char25" minOccurs="0" />
<xsd:element name="PCharg" type="n0:char11" minOccurs="0" />
<xsd:element name="PIqain" type="n0:char1" minOccurs="0" />
<xsd:element name="PLgnum" type="n0:char3" minOccurs="0" />
<xsd:element name="PLgort" type="n0:char4" minOccurs="0" />
<xsd:element name="PLirtn" type="n0:char1" minOccurs="0" />
<xsd:element name="PMacid" type="n0:char30" minOccurs="0" />
<xsd:element name="PMatnr" type="n0:char18" minOccurs="0" />
<xsd:element name="PMblnr" type="n0:char12" minOccurs="0" />
<xsd:element name="PMenge" type="n0:char15" minOccurs="0" />
<xsd:element name="PNlpla" type="n0:char15" minOccurs="0" />
<xsd:element name="PNobox" type="n0:char10" minOccurs="0" />
<xsd:element name="PPdaid" type="n0:char20" minOccurs="0" />
<xsd:element name="PPsn" type="n0:char15" minOccurs="0" />
<xsd:element name="PUname" type="n0:char12" minOccurs="0" />
<xsd:element name="PWerks" type="n0:char4" minOccurs="0" />
<xsd:element name="TLog" type="tns:TableOfVife" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Binding URL
I need to call a Web Service, created by someone else, from a .Net C# application.
The web service requires me to send a list of items ("articles"), without enclosing them in a parent element. This is a simplified illustration of the "desired" look of the call:
<body>
<info>something</info>
<moreinfo>something else</moreinfo>
<article>
<articleno>123</articleno>
</article>
<article>
<articleno>456</articleno>
</article>
</body>
On my end, the articles is a generic List<Article>, and my call to the web service tends to contain something looking more like this:
<body>
<info>something</info>
<moreinfo>something else</moreinfo>
<articles><!-- parent element -->
<article>
<articleno>123</articleno>
</article>
<article>
<articleno>456</articleno>
</article>
</articles><!-- parent element end -->
</body>
The WSDL file from the web service is corrupted, so I've hade to manually create a working subset of the functions in it that I need. Using that "hand coded" WSDL I add a Service Reference using Visual Studio 2013.
I have been trying to solve the problem by modifying the WSDL, and by modifying the code that is created by Visual Studio when adding the service reference, but so far I haven't succeeded.
I've bee trying various attributes for the list parameter, such as XmlElement, XmlIgnore, MessageHeaderArrayAttribute and others, but to be honest I don't know how they work or which ones could actually be useful in this scenario.
Can the WSDL be altered to make Visual Studio's auto generated code create the correct output when calling the web service? (Preferred solution)
Or is there a way to force soap serialization to produce the list of articles without an enclosing element? (Acceptable solution)
Here is a simplified version of the relevant (as far as I can tell) portions of the WSDL
<xsd:element name="PriceRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="1" name="info" type="xsd:string" />
<xsd:element minOccurs="0" maxOccurs="1" name="moreinfo" type="xsd:string" />
<xsd:element minOccurs="0" maxOccurs="1" name="articles" type="tns:ArrayOfArticlestructObj" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
...
<xsd:complexType name="ArticlestructObj">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="1" name="articleno" type="xsd:string" />
<xsd:element minOccurs="0" maxOccurs="1" name="otherinfo..." type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ArticlestructObj" type="tns:ArticlestructObj" />
<xsd:complexType name="ArrayOfArticlestructObj">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="ArticlestructObj" nillable="true" type="tns:Articlestruct" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ArrayOfArticlestruct" type="tns:ArrayOfArticlestruct" />
I am a noob on WSDL as well as on StackOverflow, so please excuse me if this question is hard to read.
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.
Does anyone have an idea about how keep track of a paths in xsd in deep-first traverse
For example: if I have this schema,
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:books" xmlns:bks="urn:books">
<xsd:element name="books" type="bks:BooksForm"/>
<xsd:complexType name="BooksForm">
<xsd:sequence>
<xsd:element name="book" type="bks:BookForm" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookForm">
<xsd:sequence>
<xsd:element name="author" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="genre" type="xsd:string"/>
<xsd:element name="price" type="xsd:float" />
<xsd:element name="pub_date" type="xsd:date" />
<xsd:element name="review" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
how can I get like this output in c#
path1 : books.book.author
path2 : books.book.title
.. so on
for any schema structure
does anyone have an idea about this or any good starting points
thanks in advance
thanks for reply
I tried to code your advice but I am still getting stuck
while (r.Read())
{
switch (r.Name)
{
case "xsd:element":
myStringBuilder.Append(r.GetAttribute("name"));
break;
case "xsd:complexType":
checkComplex(r);
wholepath += r.GetAttribute("name");
//this will only concatenate complex elements only
Console.WriteLine("checkComplexcaller{1}", wholepath);
break;
}
}
for recursive part.. I did
public static void checkComplex(/*what I should send here*/)
{
if (r.GetAttribute("name") == "xsd:complexType")
{
//What I sould to do for this recursive
}
else if (r.GetAttribute("name") == "xsd:element")
{
myStringBuilder.Append(r.GetAttribute("name"));
}
}
How could setup the path correctly
If I am getting this right: (pseudocode)
(make a xml document of the xsd)
foreach node of type xsd:element:
track path to the node as input
apend it with values of 'name' and 'type' attributes
if its a complex type: apply this recursively on all elements
I'm currently in the process of creating a WCF webservice which should be compatible with WS-I Basic Profile 1.1. I'm using a wsdl-first approach (actually for the first time), defining first the xsd for the complex types, the WSDL and then using svcutil.exe for generating the according server as well as client-side interfaces/proxies. So far everything works fine. Then I decided to add a fault to my WSDL.
Regenerating with svcutil succeeded, but then I noticed that my generated fault doesn't have the properties I defined in my xsd file (which is imported by my WSDL).
complex data type xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://myprod.services.mycompany.com/groups_v1.xsd"
targetNamespace="http://myprod.services.mycompany.com/groupsfault_v1.xsd">
<xsd:complexType name="groupsFault">
<xsd:sequence>
<xsd:element name="code" type="xsd:int"/>
<xsd:element name="message" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Fault XSD definition
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://myprod.services.mycompany.com/groups_v1.xsd"
targetNamespace="http://myprod.services.mycompany.com/groups_v1.xsd">
<xsd:complexType name="group">
<xsd:sequence>
<xsd:element name="groupDescD" type="xsd:string" />
<xsd:element name="groupDescI" type="xsd:string" />
<xsd:element name="groupProtNr" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
WSDL using both of the above XSDs
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions name="Groups_v1.wsdl"
targetNamespace="http://myprod.services.mycompany.com/groups_v1.wsdl"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://myprod.services.mycompany.com/groups_v1.wsdl"
xmlns:fault="http://myprod.services.mycompany.com/groupsfault_v1.xsd"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema targetNamespace="http://myprod.services.mycompany.com/groups_v1.wsdl"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:groups="http://myprod.services.mycompany.com/groups_v1.xsd">
<import namespace="http://myprod.services.mycompany.com/groups_v1.xsd" schemaLocation="./Groups.xsd"/>
<import namespace="http://myprod.services.mycompany.com/groupsfault_v1.xsd" schemaLocation="./GroupsFault.xsd"/>
<xsd:element name="getGroupList">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="StationProtNr" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getGroupListResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="group" type="groups:group" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="groupsFault">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="groupsFault" type="fault:groupsFault"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getGroupList">
<wsdl:part element="tns:getGroupList" name="parameters" />
</wsdl:message>
<wsdl:message name="getGroupListResponse">
<wsdl:part element="tns:getGroupListResponse" name="parameters" />
</wsdl:message>
<wsdl:message name="groupsFault">
<wsdl:part name="parameters" element="tns:groupsFault" />
</wsdl:message>
<wsdl:portType name="Groups_v1">
<wsdl:operation name="getGroupList">
<wsdl:input name="getGroupList" message="tns:getGroupList"/>
<wsdl:output name="getGroupListResponse" message="tns:getGroupListResponse"/>
<wsdl:fault name="getGroupListFault" message="tns:groupsFault" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Groups_v1_SOAPBinding" type="tns:Groups_v1">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getGroupList">
<soap:operation soapAction="http://myprod.services.mycompany.com/groups_v1/getGroupList" />
<wsdl:input name="getGroupList">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getGroupListResponse">
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="getGroupListFault">
<soap:fault name="getGroupListFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="getGroupList">
<wsdl:port binding="tns:Groups_v1_SOAPBinding" name="GroupsSOAP">
<soap:address location="http://myprod.services.mycompany.com/groups_v1" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Generated .Net fault object
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Xml.Serialization.XmlSchemaProviderAttribute("ExportSchema")]
[System.Xml.Serialization.XmlRootAttribute(IsNullable=false)]
public partial class groupFault : object, System.Xml.Serialization.IXmlSerializable
{
private System.Xml.XmlNode[] nodesField;
private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName("groupFault", "http://sicp.services.siag.it/groups_v1.wsdl");
public System.Xml.XmlNode[] Nodes
{
get
{
return this.nodesField;
}
set
{
this.nodesField = value;
}
}
public void ReadXml(System.Xml.XmlReader reader)
{
this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(reader);
}
public void WriteXml(System.Xml.XmlWriter writer)
{
System.Runtime.Serialization.XmlSerializableServices.WriteNodes(writer, this.Nodes);
}
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public static System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet schemas)
{
System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(schemas, typeName);
return typeName;
}
}
Is this ok?? I'd expect to have an object created that contains properties for "code" and "message" s.t. you can then throw it by using something like
...
throw new FaultException<groupFault>(new groupFault { code=100, message="error" });
...
(sorry for the lower-case type definitions, but this is generated code from the WSDL)
Why doesn't the svcutil.exe generate those properties??
Some sources on the web suggested to add the /useSerializerForFaults option of svcutil. I tried it, it doesn't work giving me an exception that the fault type is missing on the wsdl:portType declaration. Validation with several other tools succeeded however.
My command line output (maybe that helps for someone to identify any problems):
C:\>svcutil /out:IGroupsServi
ce.cs /n:*,MyCompany.MyProduct.MyModule /UseSerializerForFaults *.wsdl *.xsd
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation. All rights reserved.
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.Se
rviceModel.Description.XmlSerializerMessageContractImporter
Error: The datatype 'http://myprod.services.mycompany.com/groups_v1.wsdl:groupsFault' is
missing.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://myprod.services.mycompany.com/groups_v1.wsdl']/wsdl:portType[#name='Groups_v1']
Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is de
pendent on.
XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://myprod.services.mycompany.com/groups_v1.wsdl']/wsdl:portType[#name='Groups_v1']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://myprod.services.mycompany.com/groups_v1.wsdl']/wsdl:binding[#name='Groups_v1_SOAPBinding']
Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is depend
ent on.
XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='http://myprod.services.mycompany.com/groups_v1.wsdl']/wsdl:binding[#name='Groups_v1_SOAPBinding']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://myprod.services.mycompany.com/groups_v1.wsdl']/wsdl:service[#name='getGroupList']/wsdl:port[#name='Gr
oupsSOAP']
Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata docu
ments did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assembl
ies. Verify that you passed all the metadata documents to the tool.
Warning: If you would like to generate data contracts from schemas make sure to
use the /dataContractOnly option.
C:\>
Any help is VERY appreciated :) thx
I can give you an example of a fault that is being correctly generated for me through svcutil (with /useSerializerForFaults):
<xsd:schema targetNamespace="http://myproduct.mycompany.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:complexType name="MyError">
<xsd:sequence>
<!-- other stuff -->
<xsd:element name="description" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Is it possible that you are simply missing the namespace for your types?
This is the generated code:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://myproduct.mycompany.com/")]
public partial class MyError
{
// other stuff
private string descriptionField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 1)]
public string description
{
get
{
return this.descriptionField;
}
set
{
this.descriptionField = value;
}
}
}
And this is my full svcutil cmd line statement (note that I am generating a service reference for a given existing service - but it shouldn't make much of a difference in terms of code generation):
svcutil /t:code /out:C:\MyRepository\GeneratedCode\MyServiceReference.cs /n:*,myproduct.mycompany.servicereference /UseSerializerForFaults C:\MyRepository\*.wsdl C:\MyRepository\*.xsd /config:C:\MyRepository\GeneratedCode\MyServiceReference.config
I think your problem is that you need to add elementFormDefault="qualified" as an attribute to the xsd:schema part of your wsdl. That worked for me.