WCF返回端点未在实时中找到

时间:2014-03-03 19:30:38

标签: .net json wcf web-config endpoint

我在共享环境上托管了一个WCF服务,它包含两种不同的方法。一个是返回所需的输出,另一个是端点未找到异常,这是我验证用户的主要方法。

这里描述了这个场景:

我的Iservice.cs如下

[OperationContract]
[WebInvoke(Method="GET", UriTemplate = "Data?Id={id}", ResponseFormat=WebMessageFormat.Json)]
string GetData(string id);

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "Login?InstId={inst}&UserId={user}&pwd={pwd}", ResponseFormat = WebMessageFormat.Json)]
string Authenticate(string inst, string user, string pwd);

然后通过DAL验证用户详细信息,这是正常工作。我的网络配置如下:

  <system.serviceModel>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True">
    </serviceHostingEnvironment>-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="True">
    </serviceHostingEnvironment>
    <services>
      <service name="WCFDemo.Service1">
        <endpoint address="http://www.ekotri.com/Service1.svc" behaviorConfiguration="restfulBehavior"
                  binding="webHttpBinding" listenUri="/" bindingConfiguration="" contract="WCFDemo.IService1">
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://www.ekotri.com" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restfulBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="restfulBehavior">
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

GetData工作正常,但Authenticate给出了端点未找到错误。它在本地IIS上工作正常。

3 个答案:

答案 0 :(得分:1)

尝试此配置:

<system.serviceModel>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True">
</serviceHostingEnvironment>-->
<serviceHostingEnvironment multipleSiteBindingsEnabled="True">
</serviceHostingEnvironment>
<services>
  <service name="WCFDemo.Service1">
    <endpoint address="rest" behaviorConfiguration="restfulBehavior"
              binding="webHttpBinding" contract="WCFDemo.IService1">
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://www.ekotri.com/Service1.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="restfulBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="restfulBehavior">
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

我在visual studio的默认WCF应用程序项目上测试了它并没有任何问题。

答案 1 :(得分:1)

尝试更改您的界面

[OperationContract]
 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Login/{inst}/{user}/{pwd}",
    BodyStyle = WebMessageBodyStyle.Bare)]
string Authenticate(string inst, string user, string pwd);

放置此配置,

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="customBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="asmx" name="WCFDemo.Service1">
    <endpoint address="basic" binding="basicHttpBinding" name="httpEndPoint" contract="WCFDemo.IService1"/>
    <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="webBehavior" name="webEndPoint" contract="WebApplication1.IService"/>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>
<behaviors>
    <endpointBehaviors>
        <behavior name="webBehavior">
            <webHttp />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior name="asmx">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

答案 2 :(得分:1)

当您尝试点击登录方法时,您使用的是什么网址?

根据您的服务文件,您使用的网址模板是

Login?InstId={inst}&UserId={user}&pwd={pwd}

此外,在您的配置文件中,您将其绑定到特定的域/ URL路径

<endpoint address="http://www.ekotri.com/Service1.svc" behaviorConfiguration="restfulBehavior"
                  binding="webHttpBinding" listenUri="/" bindingConfiguration="" contract="WCFDemo.IService1">

根据这两条信息,预期的访问路径为

http://www.ekotri.com/Service1.svc/Login?InstId={inst}&UserId={user}&pwd={pwd}

如果我使用该模板url并插入一些假值..

Service Action URL

此网址返回“False”,这是预期的。