代码之家  ›  专栏  ›  技术社区  ›  Slauma

通过代理服务器连接到WCF服务时出现奇怪的异常

  •  5
  • Slauma  · 技术社区  · 15 年前

    “例外” “在下列情况下发生:

    [ServiceContract(ProtectionLevel=ProtectionLevel.None)]
    public interface IMyService
    {
        [OperationContract]
        [FaultContract(typeof(MyFault))]
        List<MyDto> MyOperation(int param);
    
        // other operations
    }
    
    public class MyService : IMyService
    {
        public List<MyDto> MyOperation(int param)
        {
            // Do the business stuff and return a list of MyDto
        }
    
        // other implementations
    }
    

    MyFault MyDto [DataContract] 属性,每个属性只有三个 [DataMember] 类型 string, int and int?

    此服务与ASP.NET应用程序一起托管在Win 2008服务器上的IIS 7.0中。我正在使用SVC文件 MyService.svc 它直接位于网站的根目录中。web.config中的服务配置如下:

    <system.serviceModel>
      <services>
        <service name="MyServiceLib.MyService">
          <endpoint address="" binding="wsHttpBinding"
              bindingConfiguration="wsHttpBindingConfig" 
              contract="MyServiceLib.IMyService" />
        </service>
      </services>
      <bindings>
        <wsHttpBinding>
          <binding name="wsHttpBindingConfig">
            <security mode="None">
              <transport clientCredentialType="None" />
            </security>
          </binding>
        </wsHttpBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior>
            <serviceMetadata httpGetEnabled="false"/>
            <serviceDebug includeExceptionDetailInFaults="false" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
    </system.serviceModel>
    

    只要我能输入地址,这似乎就行了 http://www.domain.com/MyService.svc 在浏览器中获取“这是Windows Communication Foundation服务”-欢迎页面。

    使用该服务的客户端之一是控制台应用程序:

    MyServiceClient aChannel = new MyServiceClient("WSHttpBinding_IMyService");
    List<MyDto> aMyDtoList = aChannel.MyOperation(1);
    

    它具有以下配置:

    <system.serviceModel>
      <bindings>
        <wsHttpBinding>
          <binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              bypassProxyOnLocal="true" transactionFlow="false"
              hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
              messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false"
              proxyAddress="10.20.30.40:8080" allowCookies="false">
              <readerQuotas maxDepth="32" maxStringContentLength="8192"
                  maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                  enabled="false" />
              <security mode="None">
                <transport clientCredentialType="Windows" proxyCredentialType="None"
                    realm="" />
                <message clientCredentialType="Windows"
                    negotiateServiceCredential="true" />
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://www.domain.com/MyService.svc" binding="wsHttpBinding"
              bindingConfiguration="WSHttpBinding_IMyService"
              contract="MyService.IMyService"
              name="WSHttpBinding_IMyService" />
        </client>
    </system.serviceModel>
    

    aChannel.MyOperation(1) 引发以下异常:

    相对URI不支持此操作。

    除了我删除 proxyAddress="10.20.30.40:8080" 操作没有问题。

    现在我真的不知道 . 在生产机器或开发机器上运行客户机时,是否使用代理服务器是我能看到的唯一区别。

    编辑:

    .NET框架4 .

    1 回复  |  直到 15 年前
        1
  •  8
  •   John Saunders    15 年前

    10.20.30.40:8080 http://10.20.30.40:8080 .


    以下是我的诊断思维过程,以防对任何人有所帮助:

    1. 例外通常不会说谎。他们通常说的都是真话。关键是要明白他们怎么可能说实话。
    2. 异常表示,“相对URI不支持此操作”。如果这是真的,那么它意味着一个操作正在执行,它被赋予了一个相对的URL,但它不支持相对的uri。

    在我面前,有一个相对的URI。当他删除它时,“操作”起作用了,所以我推断这是提供给不支持它们的“操作”的相对URI。

    scheme:// 在URI前面,使其相对。

    推荐文章