-1

我在 Web 应用程序中使用 WCF 服务。有两个服务,一个方法which returns string 在第一个,然后在我通过服务调用时返回DataTable一个 First one is working properly。但while calling second one我得到以下exception 在此处输入图像描述

这是服务器中的配置

  <service behaviorConfiguration="ServiceBehavior" name="RmtUsers.Menu">
    <endpoint address="" binding="wsHttpBinding" contract="IRmtUsers.IMenu">
      <identity>
        <dns value="192.168.50.35"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

  <service behaviorConfiguration="ServiceBehavior" name="RmtUsers.Product">
    <endpoint address="" binding="wsHttpBinding" contract="IRmtUsers.IProduct">
      <identity>
        <dns value="192.168.50.35"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
          </services>
      <behaviors>             <serviceBehaviors>
          <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
          </behavior>             </serviceBehaviors>         </behaviors>    </system.serviceModel>

在客户端

 <bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IMenu" closeTimeout="00:01:00" openTimeout="00:01:00"
      receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
      transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
        maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="WSHttpBinding_IProduct" closeTimeout="00:10:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
    bypassProxyOnLocal="false" transactionFlow="falsehostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" />
      </security>
    </binding>

4

2 回答 2

1

尝试跟随。

1 - 使用 SvcTraceViewer 实用程序来跟踪问题的原因。2 - 为您从 WCF 返回的数据表命名,如下所示。

new DataTable("someName");

WCF:DataTable 未使用名称初始化。注意确定为什么..

于 2012-07-11T10:47:50.037 回答
0

我尝试使用以下代码。现在它工作正常

   DataTable dt = new DataTable("products");
     dt= getData();  
     DataSet ds = new DataSet();
     ds.Tables.Add(dt);
     return ds.Tables[0];

我从Jani5e得到这个答案

于 2012-07-12T05:56:53.113 回答