2017-05-11 16 views
5

का उपयोग कर रहा एक पुराने साबुन सेवा से डबल्यूएसडीएल के आधार पर एक WCF सेवा लिख ​​रहा हूँ है। मैंने सेवा अनुबंध उत्पन्न करने के लिए svcutil का उपयोग किया और जिस साइट पर मैं इसे होस्ट कर रहा हूं उससे मेल खाने के लिए कुछ बदलाव किए, लेकिन जब मैं एक परीक्षण क्लाइंट से सेवा कहता हूं, तो अनुरोध ऑब्जेक्ट शून्य के रूप में आ रहा है।WCF सेवा अनुरोध अशक्त जब XmlSerializerFormat

प्रतिक्रिया सेवा लौटने भी गलत तरीके से धारावाहिक हो रही है जो मुझे यकीन है कि संबंधित है हूँ। लेकिन मैं यह नहीं समझ सकता कि यह सही ढंग से क्रमबद्ध और deserializing क्यों नहीं है।

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
[System.ServiceModel.ServiceContractAttribute(Namespace = ApuConstants.Namespace)] 
public interface IApuService 
{ 
    [System.ServiceModel.OperationContractAttribute(Action = "*", ReplyAction = "*")] 
    [System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Rpc, Use = System.ServiceModel.OperationFormatUse.Encoded)] 
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Part))] 
    [return: System.ServiceModel.MessageParameterAttribute(Name = "return")] 
    Brock.Web.Apu.Response check(Brock.Web.Apu.Request request); 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)] 
public partial class Request 
{ 

    private RequestHeader headerField; 

    private Lookup lookupField; 

    /// <remarks/> 
    public RequestHeader header 
    { 
     get 
     { 
      return this.headerField; 
     } 
     set 
     { 
      this.headerField = value; 
     } 
    } 

    /// <remarks/> 
    public Lookup lookup 
    { 
     get 
     { 
      return this.lookupField; 
     } 
     set 
     { 
      this.lookupField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)] 
public partial class RequestHeader 
{ 

    private string accountField; 

    private string idField; 

    /// <remarks/> 
    public string account 
    { 
     get 
     { 
      return this.accountField; 
     } 
     set 
     { 
      this.accountField = value; 
     } 
    } 

    /// <remarks/> 
    public string id 
    { 
     get 
     { 
      return this.idField; 
     } 
     set 
     { 
      this.idField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)] 
public partial class Part 
{ 

    private string oemField; 

    private string hicField; 

    private string skuField; 

    private string descField; 

    private int daysField; 

    private string availField; 

    private string branchField; 

    private float listField; 

    private float netField; 

    private string typeField; 

    private string certField; 

    private string statusField; 

    /// <remarks/> 
    public string oem 
    { 
     get 
     { 
      return this.oemField; 
     } 
     set 
     { 
      this.oemField = value; 
     } 
    } 

    /// <remarks/> 
    public string hic 
    { 
     get 
     { 
      return this.hicField; 
     } 
     set 
     { 
      this.hicField = value; 
     } 
    } 

    /// <remarks/> 
    public string sku 
    { 
     get 
     { 
      return this.skuField; 
     } 
     set 
     { 
      this.skuField = value; 
     } 
    } 

    /// <remarks/> 
    public string desc 
    { 
     get 
     { 
      return this.descField; 
     } 
     set 
     { 
      this.descField = value; 
     } 
    } 

    /// <remarks/> 
    public int days 
    { 
     get 
     { 
      return this.daysField; 
     } 
     set 
     { 
      this.daysField = value; 
     } 
    } 

    /// <remarks/> 
    public string avail 
    { 
     get 
     { 
      return this.availField; 
     } 
     set 
     { 
      this.availField = value; 
     } 
    } 

    /// <remarks/> 
    public string branch 
    { 
     get 
     { 
      return this.branchField; 
     } 
     set 
     { 
      this.branchField = value; 
     } 
    } 

    /// <remarks/> 
    public float list 
    { 
     get 
     { 
      return this.listField; 
     } 
     set 
     { 
      this.listField = value; 
     } 
    } 

    /// <remarks/> 
    public float net 
    { 
     get 
     { 
      return this.netField; 
     } 
     set 
     { 
      this.netField = value; 
     } 
    } 

    /// <remarks/> 
    public string type 
    { 
     get 
     { 
      return this.typeField; 
     } 
     set 
     { 
      this.typeField = value; 
     } 
    } 

    /// <remarks/> 
    public string cert 
    { 
     get 
     { 
      return this.certField; 
     } 
     set 
     { 
      this.certField = value; 
     } 
    } 

    /// <remarks/> 
    public string status 
    { 
     get 
     { 
      return this.statusField; 
     } 
     set 
     { 
      this.statusField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)] 
public partial class ResponseHeader 
{ 

    private string statusField; 

    private string reasonField; 

    private string accountField; 

    private string idField; 

    /// <remarks/> 
    public string status 
    { 
     get 
     { 
      return this.statusField; 
     } 
     set 
     { 
      this.statusField = value; 
     } 
    } 

    /// <remarks/> 
    public string reason 
    { 
     get 
     { 
      return this.reasonField; 
     } 
     set 
     { 
      this.reasonField = value; 
     } 
    } 

    /// <remarks/> 
    public string account 
    { 
     get 
     { 
      return this.accountField; 
     } 
     set 
     { 
      this.accountField = value; 
     } 
    } 

    /// <remarks/> 
    public string id 
    { 
     get 
     { 
      return this.idField; 
     } 
     set 
     { 
      this.idField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)] 
public partial class Response 
{ 

    private ResponseHeader headerField; 

    private Part[] itemsField; 

    /// <remarks/> 
    public ResponseHeader header 
    { 
     get 
     { 
      return this.headerField; 
     } 
     set 
     { 
      this.headerField = value; 
     } 
    } 

    /// <remarks/> 
    public Part[] items 
    { 
     get 
     { 
      return this.itemsField; 
     } 
     set 
     { 
      this.itemsField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)] 
public partial class Lookup 
{ 

    private string oemField; 

    private string hicField; 

    private int qtyField; 

    private string zipField; 

    /// <remarks/> 
    public string oem 
    { 
     get 
     { 
      return this.oemField; 
     } 
     set 
     { 
      this.oemField = value; 
     } 
    } 

    /// <remarks/> 
    public string hic 
    { 
     get 
     { 
      return this.hicField; 
     } 
     set 
     { 
      this.hicField = value; 
     } 
    } 

    /// <remarks/> 
    public int qty 
    { 
     get 
     { 
      return this.qtyField; 
     } 
     set 
     { 
      this.qtyField = value; 
     } 
    } 

    /// <remarks/> 
    public string zip 
    { 
     get 
     { 
      return this.zipField; 
     } 
     set 
     { 
      this.zipField = value; 
     } 
    } 
} 

और कार्यान्वयन::

यहाँ सेवा अनुबंध है

[ServiceBehavior(Namespace = ApuConstants.Namespace)] 
public class ApuService : IApuService 
{ 
    private readonly IApuServiceHandler _handler; 
    private readonly ISettingService _settingService; 

    public ApuService() 
    { 
     _handler = EngineContext.Current.Resolve<IApuServiceHandler>(); 
     _settingService = EngineContext.Current.Resolve<ISettingService>(); 
    } 

    public Response check(Request request) 
    { 
     if (Authorized(request)) 
      return _handler.ProcessRequest(request); 
     return _handler.ErrorResponse("Invalid credentials"); 
    } 

    protected bool Authorized(Request request) 
    { 
     if (request == null || request.header == null) 
      return false; 

     var settings = _settingService.LoadSetting<ApuSettings>(0); 

     if (!string.Equals(request.header.account, settings.Username, StringComparison.InvariantCultureIgnoreCase)) 
      return false; 

     if (!string.Equals(request.header.id, settings.Password)) 
      return false; 

     return true; 
    } 
} 

विन्यास:

<configuration> 
    <system.web> 
    <compilation targetFramework="4.5.1" /> 
    </system.web> 

    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ApuBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
    </bindings> 
    <services> 
     <service name="Apu.WebService.ApuService" behaviorConfiguration="ApuBehavior"> 
     <endpoint address="" binding="basicHttpBinding" contract="Web.Apu.IApuService" bindingNamespace="http://www.testurl.com/apu" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

(OperationContext.Current.RequestContext से सेवा से प्राप्त अनुरोध .RequestMessage):

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:15555/Plugins/Brock.Apu/Remote/ApuService.svc</To> 
    </s:Header> 
    <Body> 
     <check xmlns="http://www.testurl.com/apu"> 
      <request> 
       <header> 
        <account>apu</account> 
        <id>apu001!</id> 
       </header> 
       <lookup> 
        <hic>323-01327</hic> 
        <oem>5014351AB</oem> 
        <qty>2</qty> 
        <zip>85304</zip> 
       </lookup> 
      </request> 
     </check> 
    </Body> 
</Envelope> 

रिस्पांस सेवा (जो गलत तरीके से धारावाहिक है) द्वारा भेजे गए:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <q1:checkResponse xmlns:q1="http://www.testurl.com/apu"> 
      <return href="#id1"/> 
     </q1:checkResponse> 
     <q2:Response id="id1" xsi:type="q2:Response" xmlns:q2="http://www.testurl.com/apu"> 
      <header href="#id2"/> 
     </q2:Response> 
     <q3:ResponseHeader id="id2" xsi:type="q3:ResponseHeader" xmlns:q3="http://www.testurl.com/apu"> 
      <status xsi:type="xsd:string">no</status> 
      <reason xsi:type="xsd:string">Invalid credentials</reason> 
      <account xsi:type="xsd:string"/> 
      <id xsi:type="xsd:string"/> 
     </q3:ResponseHeader> 
    </s:Body> 
</s:Envelope> 
+0

जब कोई कहता है 'कुछ बदलाव किए हैं', मुझे लगता है कि करने के लिए है कि समस्या यह है करते हैं। –

+0

क्या आपने wsdl.exe को चेक आउट किया है? https://msdn.microsoft.com/en-us/library/7h3ystb6(v=vs.100).aspx। पुरानी .asmx सेवाएं प्रॉक्सी पीढ़ी के लिए उपयोग करती हैं। सेवा की उम्र के आधार पर आपको अलग-अलग परिणाम मिल सकते हैं। –

+0

@JssDwt - बिलकुल नहीं। मैं डेटा अनुबंध क्रमिकरण का उपयोग करने के लिए सेवा को और संशोधित करने में सक्षम था और यह ठीक काम करता था। हालांकि, मुझे एक्सएमएल क्रमबद्धता का उपयोग करने की आवश्यकता है। समस्या संशोधन नहीं है। यह इसे संशोधित करने का सही तरीका जान रहा है। यह प्रोग्रामिंग दुनिया के लिए एक गरीब की तलाश है जब हम यह कहते हुए हम पुराने नहीं बदल सकते (या इस मामले में pregenerated) कोड हमारी जरूरतों को पूरा करने के लिए शुरू है। –

उत्तर

0

अप का पालन करें: यह सेवा अनुबंध पता चला है के रूप में मैं मूल रूप से तैनात तब भी वह अच्छे। यह अनुरोध का प्रारूप है जो गलत था। एक सरल इनलाइन एक्सएमएल संरचना के बजाय, deserializer इस उम्मीद कर रहा था:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <ns1:check xmlns:ns1="http://www.testurl.com/apu" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
      <request href="#id0"/> 
     </ns1:check> 
     <multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://www.testurl.com/apu" id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Request"> 
      <header href="#id1"/> 
      <lookup href="#id2"/> 
     </multiRef> 
     <multiRef xmlns:ns3="http://www.testurl.com/apu" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:RequestHeader"> 
      <account xsi:type="xsd:string"></account> 
      <id xsi:type="xsd:string"></id> 
     </multiRef> 
     <multiRef xmlns:ns4="http://www.testurl.com/apu" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:Lookup"> 
      <oem xsi:type="xsd:string">6C3Z13008BB</oem> 
      <hic xsi:type="xsd:string"/> 
      <qty href="#id3"/> 
      <zip xsi:type="xsd:string">70764</zip> 
     </multiRef> 
     <multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int">1</multiRef> 
    </soapenv:Body> 
</soapenv:Envelope> 

मैं इस हमारे ग्राहक कच्चे अनुरोध लॉग ऑन अपने ग्राहक द्वारा भेजे गए हो रही करने के बाद पता लगा।

1

ऐसा लगता है कि Response की तरह एक आंशिक वर्ग है। क्या कोई और टुकड़ा है, शायद दूसरी फाइल में? क्या वह दूसरा टुकड़ा धारावाहिक है? ResponseHeader और Part के लिए समान प्रश्न?

मैं आमतौर पर [Serializable] डेकोरेटर का उपयोग करें।

कक्षा के भीतर public float list पर कीवर्ड सूची के साथ कोई समस्या हो सकती है।

+0

किसी भी आंशिक के लिए कोई अन्य भाग नहीं हैं। डेटा ऑब्जेक्ट्स पहले से ही Serializable चिह्नित हैं ([System.SerializableAttribute()])। सी # एक केस संवेदनशील भाषा है, इसलिए सूची वर्ग के साथ एक कम मामला "सूची" भ्रमित नहीं किया जाएगा। इसके अलावा न तो "सूची" और न ही "सूची" सी # में आरक्षित कीवर्ड हैं। –