Chaz

Chaz

  • NA
  • 1
  • 4.2k

Struggle to build WCF service based on WSDL from partner

Feb 14 2014 12:16 PM
I have received a WSDL and XSD from our trading partner. The WSDL represents a service that I must create and then expose so that the trading partner can call in with SalesOrderAcknowledgments.  
 
I have processed the WSDL using  svcutil.exe  Runtime Version:4.0.30319.1008.  SvcUtil generates a C# class with the contract interface and classes to support the client. I have built a service that consumes the contract and exposes it with http binding.  
 
I created a test client to try and consume the service.  I turn on my service and use Add Service Reference to setup the client side of the transaction.

The Problem 

When I use the service code generated by svcutil, the service reference code does not contain the necessary implementation for the client.
 
I found what seems like a fix!
I can modify the code generated by svcutil.  Instead of [OperationContractAttribute] I change it to use [OperationContract].  Now, I turn on the host and add a service reference and the generated client code is there...but the Operation Action is different from the original WSDL.

Code Examples

The WSDL 

<?xml version = "1.0" encoding = "UTF-8"?>
<wsdl:definitions targetNamespace = "http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt" xmlns = "http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt" xmlns:csp = "http://www.partner.com/schemas/SNS/SalesOrderAcknowledgmentReceipt" xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl = "http://schemas.xmlsoap.org/wsdl/" xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
 <wsdl:import location = "../../../../BCSchemas/SOAP/SalesOrderAcknowledgmentReceipt/1.0/SalesOrderAcknowldgementReceipt/SalesOrderAcknowledgmentReceipt.xsd" namespace = "http://www.partner.com/schemas/SNS/SalesOrderAcknowledgmentReceipt"/>
<!-- Flow SalesOrderAcknowledgmentReceipt -->
<wsdl:message name = "SalesOrderAcknowledgmentReceiptRequests">
<wsdl:part element = "csp:SalesOrderAcknowledgmentReceipt" name = "SalesOrderAcknowledgmentReceipt"/>
</wsdl:message>
<wsdl:message name = "SalesOrderAcknowledgmentReceiptResponse">
<wsdl:part element = "csp:TechnicalPartnerAcknowledgmentReceipt" name = "TechnicalPartnerAcknowledgmentReceipt"/>
</wsdl:message>
<wsdl:portType name = "SalesOrderAcknowledgmentReceiptPortType">
<wsdl:operation name = "SalesOrderAcknowledgmentReceipt">
<wsdl:input message = "SalesOrderAcknowledgmentReceiptRequests"/>
<wsdl:output message = "SalesOrderAcknowledgmentReceiptResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name = "BindingSalesOrderAcknowledgmentReceipt" type = "SalesOrderAcknowledgmentReceiptPortType">
<soap:binding style = "document" transport = "http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name = "SalesOrderAcknowledgmentReceipt">
<soap:operation soapAction = "http://www.partner.com/schemas/SNS/SalesOrderAcknowledgmentReceipt/SalesOrderAcknowledgmentReceipt"/>
<wsdl:input>
<soap:body use = "literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use = "literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name = "SalesOrderAcknowledgmentReceipt">
<wsdl:port binding = "BindingSalesOrderAcknowledgmentReceipt" name = "SalesOrderAcknowledgmentReceipt">
<soap:address location = "http://localhost.dev"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
 

 Portion of the SvcUtil Output

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt", ConfigurationName = "SalesOrderAcknowledgmentReceiptPortType")]
public interface SalesOrderAcknowledgmentReceiptPortType
{
  // CODEGEN: Generating message contract since the operation SalesOrderAcknowledgmentReceipt is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(Action = "http://www.partner.com/schemas/SNS/SalesOrderAcknowledgmentReceipt/SalesOrderA" +
"cknowledgmentReceipt", ReplyAction = "*")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
SalesOrderAcknowledgmentReceiptResponse SalesOrderAcknowledgmentReceipt(SalesOrderAcknowledgmentReceiptRequest request);
}

Here's the broken Service Reference Code generated based on [OperationContractAttribute]

 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt", ConfigurationName="SOAckService2Ref.SalesOrderAcknowledgmentReceiptPortType")]
public interface SalesOrderAcknowledgmentReceiptPortType {
}

 The Change to the Contract Interface that seems to make it work

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt", ConfigurationName = "SalesOrderAcknowledgmentReceiptPortType")]
public interface SalesOrderAcknowledgmentReceiptPortType
{
// CODEGEN: Generating message contract since the operation SalesOrderAcknowledgmentReceipt is neither RPC nor document wrapped.
[System.ServiceModel.OperationContract]
[System.ServiceModel.XmlSerializerFormatAttribute()]
SalesOrderAcknowledgmentReceiptResponse SalesOrderAcknowledgmentReceipt(SalesOrderAcknowledgmentReceiptRequest request);
}

 Here's the Service Reference Code generated based on [OperationContract]

 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt", ConfigurationName="SOAckService1Ref.SalesOrderAcknowledgmentReceiptPortType")]
public interface SalesOrderAcknowledgmentReceiptPortType {eur
// CODEGEN: Generating message contract since the operation SalesOrderAcknowledgmentReceipt is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(Action="http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt/SalesOrderAckn" +
"owledgmentReceiptPortType/SalesOrderAcknowledgmentReceipt", ReplyAction="http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt/SalesOrderAckn" +
"owledgmentReceiptPortType/SalesOrderAcknowledgmentReceiptResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
SOAConsole.SOAckService1Ref.SalesOrderAcknowledgmentReceiptResponse SalesOrderAcknowledgmentReceipt(SOAConsole.SOAckService1Ref.SalesOrderAcknowledgmentReceiptRequest request);
}
 
See the incorrect action? http://www.partner.com/wsdl/SNS/SalesOrderAcknowledgmentReceipt/SalesOrderAcknowledgmentReceiptPortType/SalesOrderAcknowledgmentReceipt