此 WCF 错误的原因可能是什么?

发布于 2024-12-04 20:36:55 字数 6086 浏览 0 评论 0 原文

我的 WCF 服务[使用 basicHttpBinding] 托管在 IIS 6 上。我能够在 IE 浏览器中的服务 url 中使用 ?wsdl 访问它。

我的 winforms 客户端中有一个表示层,我使用 VS.Net 中的 ServiceReferences 选项添加了该服务的引用,然后生成了一个代理。

当我调用此服务上的方法时,出现此异常。我在这里可能会缺少什么?谢谢。

“值不能为空。参数名称 uri。”在 System.ServiceModel.Description.ClientViaBehavior..ctor(Uri uri)
在 System.ServiceModel.Configuration.ClientViaElement.CreateBehavior() 在 System.ServiceModel.Description.ConfigLoader.LoadBehaviors[T](ServiceModelExtensionCollectionElement1 behaviorElement,KeyedByTypeCollection1 行为,布尔值 常见行为)

在 System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint,字符串配置名称)

在 System.ServiceModel.ChannelFactory.ApplyConfiguration(字符串 配置名称)位于 System.ServiceModel.ChannelFactory.InitializeEndpoint(字符串 配置名称、EndpointAddress 地址)位于 System.ServiceModel.ChannelFactory1..ctor(字符串 端点配置名称、端点地址远程地址)位于 System.ServiceModel.EndpointTrait1.CreateSimplexFactory() 在 System.ServiceModel.EndpointTrait1.CreateChannelFactory() 位于 System.ServiceModel.ClientBase1.CreateChannelFactoryRef(EndpointTrait1 端点特征)在 System.ServiceModel.ClientBase1.InitializeChannelFactoryRef() 位于 System.ServiceModel.ClientBase`1..ctor() 位于 C:\Presentation\Service 中的TestingClient..ctor() References\ServiceReference1\Reference.cs:第 268 行

这是我的服务器和客户端的配置 xml:

*服务器:

<system.serviceModel> 
    <bindings> 
      <basicHttpBinding> 
        <binding name="ProviderBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
               receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" 
               bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
               maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="Transport"> 
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
          </security> 
        </binding> 
      </basicHttpBinding> 
    </bindings> 
    <services> 
      <service name="PTSWeb.PriceTestingService" behaviorConfiguration="PTSWeb.Service1Behavior"> 
        <!-- Service Endpoints --> 
        <endpoint address="" binding="basicHttpBinding" contract="PTSWeb.IPriceTesting"> 
          <identity> 
            <dns value="localhost"/> 
          </identity> 
        </endpoint> 
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
      </service> 
    </services> 
    <behaviors> 
      <serviceBehaviors> 
        <behavior name="PTSWeb.Service1Behavior"> 
                <serviceMetadata httpGetEnabled="true"/> 
          <serviceDebug includeExceptionDetailInFaults="true"/> 
        </behavior> 
      </serviceBehaviors> 
    </behaviors> 
  </system.serviceModel>

*客户端:

<system.serviceModel> 
    <client> 
      <endpoint address="http://localhost/PTSWeb/PTSWebService.svc" 
        behaviorConfiguration="PTSWeb.Service1Behavior" binding="basicHttpBinding" 
        bindingConfiguration="IPriceTestingBinding" contract="IPriceTesting" 
        name="IPriceTestingPort" /> 
      <endpoint address="https://qaserver/webservice" 
                binding="basicHttpBinding" bindingConfiguration="ProviderBinding" 
                contract="Provider" name="ProviderPort" />      
    </client> 
    <bindings> 
      <basicHttpBinding> 
        <binding name="IPriceTestingBinding" closeTimeout="00:01:00" 
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
          maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
          useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
            maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="None" /> 
        </binding> 
        <binding name="ProviderBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
               receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" 
               bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
               maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="Transport"> 
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
          </security> 
        </binding> 
      </basicHttpBinding> 
    </bindings> 

    <behaviors> 
      <endpointBehaviors>      
        <behavior name="PTSWeb.Service1Behavior"> 
          <clientVia/> 
        </behavior> 
      </endpointBehaviors> 
  </behaviors> 
  </system.serviceModel>

My WCF service[using basicHttpBinding] is hosted on IIS 6.Am able to access it using ?wsdl in the service url in IE browser .

I've a presenation layer in my winforms client and I added the reference of this service using ServiceReferences option in VS.Net which then generated a proxy.

When I call a method on this service, am getting this exception.What could I be missing here ?Thanks.

"Value cannot be null.Parameter name uri." at
System.ServiceModel.Description.ClientViaBehavior..ctor(Uri uri)
at System.ServiceModel.Configuration.ClientViaElement.CreateBehavior()
at
System.ServiceModel.Description.ConfigLoader.LoadBehaviors[T](ServiceModelExtensionCollectionElement1
behaviorElement, KeyedByTypeCollection
1 behaviors, Boolean
commonBehaviors)

at
System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint
serviceEndpoint, String configurationName)

at System.ServiceModel.ChannelFactory.ApplyConfiguration(String
configurationName) at
System.ServiceModel.ChannelFactory.InitializeEndpoint(String
configurationName, EndpointAddress address) at
System.ServiceModel.ChannelFactory1..ctor(String
endpointConfigurationName, EndpointAddress remoteAddress) at
System.ServiceModel.EndpointTrait
1.CreateSimplexFactory() at
System.ServiceModel.EndpointTrait1.CreateChannelFactory() at
System.ServiceModel.ClientBase
1.CreateChannelFactoryRef(EndpointTrait1
endpointTrait) at
System.ServiceModel.ClientBase
1.InitializeChannelFactoryRef() at
System.ServiceModel.ClientBase`1..ctor() at
TestingClient..ctor() in C:\Presentation\Service
References\ServiceReference1\Reference.cs:line 268

Here is my config xml for server and client:

*Server:

<system.serviceModel> 
    <bindings> 
      <basicHttpBinding> 
        <binding name="ProviderBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
               receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" 
               bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
               maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="Transport"> 
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
          </security> 
        </binding> 
      </basicHttpBinding> 
    </bindings> 
    <services> 
      <service name="PTSWeb.PriceTestingService" behaviorConfiguration="PTSWeb.Service1Behavior"> 
        <!-- Service Endpoints --> 
        <endpoint address="" binding="basicHttpBinding" contract="PTSWeb.IPriceTesting"> 
          <identity> 
            <dns value="localhost"/> 
          </identity> 
        </endpoint> 
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
      </service> 
    </services> 
    <behaviors> 
      <serviceBehaviors> 
        <behavior name="PTSWeb.Service1Behavior"> 
                <serviceMetadata httpGetEnabled="true"/> 
          <serviceDebug includeExceptionDetailInFaults="true"/> 
        </behavior> 
      </serviceBehaviors> 
    </behaviors> 
  </system.serviceModel>

*Client:

<system.serviceModel> 
    <client> 
      <endpoint address="http://localhost/PTSWeb/PTSWebService.svc" 
        behaviorConfiguration="PTSWeb.Service1Behavior" binding="basicHttpBinding" 
        bindingConfiguration="IPriceTestingBinding" contract="IPriceTesting" 
        name="IPriceTestingPort" /> 
      <endpoint address="https://qaserver/webservice" 
                binding="basicHttpBinding" bindingConfiguration="ProviderBinding" 
                contract="Provider" name="ProviderPort" />      
    </client> 
    <bindings> 
      <basicHttpBinding> 
        <binding name="IPriceTestingBinding" closeTimeout="00:01:00" 
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
          maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
          useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
            maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="None" /> 
        </binding> 
        <binding name="ProviderBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
               receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" 
               bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
               maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="Transport"> 
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
          </security> 
        </binding> 
      </basicHttpBinding> 
    </bindings> 

    <behaviors> 
      <endpointBehaviors>      
        <behavior name="PTSWeb.Service1Behavior"> 
          <clientVia/> 
        </behavior> 
      </endpointBehaviors> 
  </behaviors> 
  </system.serviceModel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法回应 2024-12-11 20:36:55

在客户端配置行为中,您有一个未定义任何 URI 的 ClientVia 元素。删除此行为或定义 via Uri。

这很好地解释了客户端行为的目标和用法:http://blogs.msdn.com/b/anilkumargupta/archive/2009/05/16/wcf-intermediate-service- Between-client-and-server.aspx

In the client config behavior, you have a ClientVia element without any URI defined. Either remove this behavior or define the via Uri.

This quite well explain the goal and usage of the clientvia behavior : http://blogs.msdn.com/b/anilkumargupta/archive/2009/05/16/wcf-intermediate-service-between-client-and-server.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文