2013-04-03 14 views
5

मेरे पास 2 नामस्थानों वाला एक डब्ल्यूएसडीएल दस्तावेज़ है, और मैं SVCUTIL.EXE का उपयोग कर प्रॉक्सी कक्षाएं उत्पन्न करने का प्रयास कर रहा हूं। किसी कारण से, जेनरेट कोड में प्रकारों को डिफ़ॉल्ट नामस्थान में रखा जाता है, न कि प्रदान किए गए मानचित्रण के सही नाम में।.NET SVCUTIL नामस्थानों को ठीक से उत्पन्न नहीं करता

SvcUtil.exe/टी:

<?xml version='1.0' encoding='UTF-8'?> 
<wsdl:definitions name="TestService" 
    targetNamespace="My.Namespace.1" 
    xmlns:ns1="http://schemas.xmlsoap.org/soap/http" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:tns="My.Namespace.1" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <wsdl:types> 
     <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="My.Namespace.1" xmlns:ns1="My.Namespace.2" xmlns:tns="My.Namespace.1" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
      <xs:import namespace="My.Namespace.2"/> 

      <xs:element name="TestOpRequest" type="tns:TestOpRequest"/> 
      <xs:element name="TestOpResponse" type="tns:TestOpResponse"/> 

      <xs:complexType name="TestOpRequest"> 
       <xs:sequence> 
        <xs:element ref="ns1:Type1"/> 
       </xs:sequence> 
      </xs:complexType> 

      <xs:complexType name="TestOpResponse"> 
       <xs:sequence> 
       </xs:sequence> 
      </xs:complexType> 

     </xs:schema> 
     <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="My.Namespace.2" xmlns:tns="My.Namespace.2" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
      <xs:element name="Type1" type="tns:Type1"/> 

      <xs:complexType name="Type1"> 
       <xs:sequence> 
        <xs:element name="prop1" type="xs:string"/> 
        <xs:element name="prop2" type="xs:string"/> 
       </xs:sequence> 
      </xs:complexType> 

     </xs:schema> 
    </wsdl:types> 

    <wsdl:message name="testOp"> 
     <wsdl:part element="tns:TestOpRequest" name="parameter"/> 
    </wsdl:message> 

    <wsdl:message name="testOpResponse"> 
     <wsdl:part element="tns:TestOpResponse" name="parameter"/> 
    </wsdl:message> 

    <wsdl:portType name="TestService"> 
     <wsdl:operation name="testOp"> 
      <wsdl:input message="tns:testOp" name="testOp"/> 
      <wsdl:output message="tns:testOpResponse" name="testOpResponse"/> 
     </wsdl:operation> 
    </wsdl:portType> 

    <wsdl:binding name="TestServiceSoapBinding" type="tns:TestService"> 
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <wsdl:operation name="testOp"> 
      <soap:operation soapAction="" style="document"/> 
      <wsdl:input name="testOp"> 
       <soap:body use="literal"/> 
      </wsdl:input> 
      <wsdl:output name="testOpResponse"> 
       <soap:body use="literal"/> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="TestService"> 
     <wsdl:port binding="tns:TestServiceSoapBinding" name="TestServicePort"> 
      <soap:address location="http://localhost/TestService"/> 
     </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

यहाँ कैसे मैं प्रॉक्सी उत्पन्न है:

यहाँ मेरी डबल्यूएसडीएल है कोड test.wsdl /n:My.Namespace.1,Test.Namespace1/n: My.Namespace.2, Test.Namespace2 /o:Test.cs

यहाँ उत्पन्न हो जाता है:

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="My.Namespace.1")] 
public partial class TestOpRequest 
{ 

    private Type1 type1Field; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Namespace="My.Namespace.2", Order=0)] 
    public Type1 Type1 
    { 
     get 
     { 
      return this.type1Field; 
     } 
     set 
     { 
      this.type1Field = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="My.Namespace.2")] 
public partial class Type1 
{ 

    private string prop1Field; 

    private string prop2Field; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Order=0)] 
    public string prop1 
    { 
     get 
     { 
      return this.prop1Field; 
     } 
     set 
     { 
      this.prop1Field = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Order=1)] 
    public string prop2 
    { 
     get 
     { 
      return this.prop2Field; 
     } 
     set 
     { 
      this.prop2Field = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="My.Namespace.1")] 
public partial class TestOpResponse 
{ 
} 
namespace Test.Namespace1 
{ 


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    [System.ServiceModel.ServiceContractAttribute(Namespace="My.Namespace.1", ConfigurationName="Test.Namespace1.TestService")] 
    public interface TestService 
    { 

     // CODEGEN: Generating message contract since the operation testOp is neither RPC nor document wrapped. 
     [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")] 
     [System.ServiceModel.XmlSerializerFormatAttribute()] 
     Test.Namespace1.testOpResponse testOp(Test.Namespace1.testOp request); 
    } 

    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] 
    public partial class testOp 
    { 

     [System.ServiceModel.MessageBodyMemberAttribute(Namespace="My.Namespace.1", Order=0)] 
     public TestOpRequest TestOpRequest; 

     public testOp() 
     { 
     } 

     public testOp(TestOpRequest TestOpRequest) 
     { 
      this.TestOpRequest = TestOpRequest; 
     } 
    } 

    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] 
    public partial class testOpResponse 
    { 

     [System.ServiceModel.MessageBodyMemberAttribute(Name="TestOpResponse", Namespace="My.Namespace.1", Order=0)] 
     public TestOpResponse TestOpResponse1; 

     public testOpResponse() 
     { 
     } 

     public testOpResponse(TestOpResponse TestOpResponse1) 
     { 
      this.TestOpResponse1 = TestOpResponse1; 
     } 
    } 

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    public interface TestServiceChannel : Test.Namespace1.TestService, System.ServiceModel.IClientChannel 
    { 
    } 

    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    public partial class TestServiceClient : System.ServiceModel.ClientBase<Test.Namespace1.TestService>, Test.Namespace1.TestService 
    { 

     public TestServiceClient() 
     { 
     } 

     public TestServiceClient(string endpointConfigurationName) : 
       base(endpointConfigurationName) 
     { 
     } 

     public TestServiceClient(string endpointConfigurationName, string remoteAddress) : 
       base(endpointConfigurationName, remoteAddress) 
     { 
     } 

     public TestServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
       base(endpointConfigurationName, remoteAddress) 
     { 
     } 

     public TestServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
       base(binding, remoteAddress) 
     { 
     } 

     [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 
     Test.Namespace1.testOpResponse Test.Namespace1.TestService.testOp(Test.Namespace1.testOp request) 
     { 
      return base.Channel.testOp(request); 
     } 

     public TestOpResponse testOp(TestOpRequest TestOpRequest) 
     { 
      Test.Namespace1.testOp inValue = new Test.Namespace1.testOp(); 
      inValue.TestOpRequest = TestOpRequest; 
      Test.Namespace1.testOpResponse retVal = ((Test.Namespace1.TestService)(this)).testOp(inValue); 
      return retVal.TestOpResponse1; 
     } 
    } 
} 

यहाँ मैं क्या nee है डी उत्पन्न करने के लिए:

namespace Test.Namespace2 
{ 
    public partial class Type1 
    { 
     .... 
    } 
} 

namespace Test.Namespace1 
{ 
    public partial class TestOpRequest 
    { 
     private Test.Namespace2 type1Field; 
     ... 
    } 

    public partial class TestOpResponse 
    { 
    } 

    public interface TestService 
    { 
     Test.Namespace1.testOpResponse testOp(Test.Namespace1.testOp request); 
    } 

    public partial class testOp 
    { 
     ... 
    } 

    public partial class testOpResponse 
    { 
     ... 
    } 

} 

किसी भी सुझाव की सराहना की जाएगी।

उत्तर

7

आप निर्दिष्ट कर सकते क्या नामस्थान आप उत्पन्न करने के लिए करना चाहते हैं:

svcutil /n:*,Test.Namespace1 (... other args for svcutil not shown) 

यह वही Test.Namespace1 करने के लिए सभी नामस्थान नक्शा होगा।

बेशक

, आप अलग-अलग नामस्थान मैप कर सकते हैं, उदाहरण के लिए अगर आपकी सेवा इस तरह परिभाषित किया गया है:

[ServiceContract(Namespace = "http://test.com/wsdl/MyFirstService")] 
public interface IMyFirstService 
{ 
} 

[ServiceContract(Namespace = "http://test.com/wsdl/MySecondService")] 
public interface IMySecondService 
{ 
} 

आप उन्हें व्यक्तिगत रूप से मैप कर सकते:

svcutil /n:http://test.com/wsdl/MyFirstService,Test.Namespace1 
     /n:http://test.com/wsdl/MySecondService,Test.Namespace2 
(etc...) 

अधिक जानकारी के लिए, ले this पर एक नज़र डालें लेकिन यदि आप मुद्दों में भी भाग लेते हैं तो this

संबंधित मुद्दे