Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Protobuf网络WCF响应为空_Wcf_Protobuf Net - Fatal编程技术网

Protobuf网络WCF响应为空

Protobuf网络WCF响应为空,wcf,protobuf-net,Wcf,Protobuf Net,我有一个WCF契约,概述了一个测试方法,该方法使用protobuf net跨WCF返回一个类的实例。我可以在测试应用程序中进行序列化和反序列化,但当我通过WCF发出请求时,响应类实例存在,但其所有属性都为null 以下是相关的配置文件和类定义: [ProtoContract] public class TestClass { [ProtoMember(1)] public int TestInt { get; set; } [ProtoMember(2)] pu

我有一个WCF契约,概述了一个测试方法,该方法使用protobuf net跨WCF返回一个类的实例。我可以在测试应用程序中进行序列化和反序列化,但当我通过WCF发出请求时,响应类实例存在,但其所有属性都为null

以下是相关的配置文件和类定义:

[ProtoContract]
public class TestClass
{
    [ProtoMember(1)]
    public int TestInt { get; set; }

    [ProtoMember(2)]
    public string TestString { get; set; }
}

...

[ServiceContract]
public interface ITestService
{
    [OperationContract]
    [ProtoBehavior]
    TestClass RunTest(int x);
}

...

<extensions>
    <behaviorExtensions>
        <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=1.0.0.282, Culture=neutral, PublicKeyToken=257b51d87d2e4d67" />
    </behaviorExtensions>
</extensions>

<endpointBehaviors>
    <behavior name="Proto.Default.EndpointBehavior">
        <protobuf />
    </behavior>
</endpointBehaviors>
<serviceBehaviors>
    <behavior name="Proto.Default.ServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata />
      <serviceAuthorization principalPermissionMode="None" />
      <serviceThrottling    maxConcurrentCalls="250"
                            maxConcurrentSessions="200"
                            maxConcurrentInstances="10" />
    </behavior>
</serviceBehaviors>

...

<services>
    <service name="WcfTestService" behaviorConfiguration="Proto.Default.ServiceBehavior">
    <endpoint address=""    binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITestService"   contract="ITestService" behaviorConfiguration="Proto.Default.EndpointBehavior" />
    <endpoint address="mex" binding="customBinding" bindingConfiguration="myMexTcpBinding" contract="IMetadataExchange" />
    <host>
        <baseAddresses>
            <add baseAddress="net.tcp://localhost:2517/TestService" />
        </baseAddresses>
    </host>
</service>

...

<client>
   <endpoint address="net.tcp://localhost:2517/TestService"
    binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITestService"
    contract="ITestService" name="TestService"
    behaviorConfiguration="Proto.Default.EndpointBehavior">
    <identity>
        <dns value="localhost" />
    </identity>
</endpoint>
</client>

我想你在这里遇到了著名的互操作性问题。请看我对这篇文章的回答:

您需要识别客户机代码所期望的Soap消息,并将正确的代码与服务返回的Soap消息同步

在本例中,您可以通过以下方式确定客户端希望如何格式化响应消息:

a. creating Service stub from WSDL using WSDL /serverInterface
b. Create a class implimenting the Service stub
c. Host the WebService in IIS and browse the help page
d. Click on operation called from list.
e. Help page shows the expected request and response soap message

对,;Mex/generation没有包含这些数字,但您可以添加它们。在单独的代码文件(相同的命名空间)中,添加

有时WCF有帮助,有时是一种痛苦(请注意,如果两端都有一个共享的DTO程序集,那么它很容易工作)


有时WCF会在每个DataMember上给出正确的ish数字,但如果出现这种情况,您可以使用一个调整来告诉protobuf使用带有偏移量的数字。

您能显示Mex生成的代理吗?有很多方法可以强迫代理服务器很好地发挥作用,但我需要看看。特别是,我关注的是标记为DataMember的成员以及他们的属性我发布了上面为TestClass生成的代码。。。除非你能在头脑中解码/编码原型:)好吧,这里不能真的责怪WCF。使用自定义序列化属性(即ProtoMember与DataMember)意味着proto-buffer-behvior实现将负责通过实现IWsdlExportExtension为WSDL生成适当的模式细节。由于不是,它将默认为成员的字母顺序。@Drew并且对于这个双重用途,protobuf net非常乐意使用DataContract/DataMember属性:)@Drew-但是,这个接口对我来说是新的;我要一个look@MarcGravel您也可能同时使用DataMemberAttribute和ProtoMemberAttribute,其中DMA帮助您进行排序,PMA帮助您获得所有protobuf特定支持。这样,您就不需要对IWsdlExport/ImportExtension执行任何特定操作。缺点是在DMA的订单和PMA的标签之间对订单概念进行了更多的编码和复制。我打赌你可以让它与IWsdlExportExtension一起工作,def。看看它。@Andy share Assembly很容易做到这一点-到目前为止,对于已经是非常定制的场景来说,这是最简单的选择
a. creating Service stub from WSDL using WSDL /serverInterface
b. Create a class implimenting the Service stub
c. Host the WebService in IIS and browse the help page
d. Click on operation called from list.
e. Help page shows the expected request and response soap message
[ProtoContract]
[ProtoPartialMember(1, "TestInt")]
[ProtoPartialMember(2, "TestString")]
partial class TestClass {}