简体   繁体   English

Web服务返回EndPointNotFoundException

[英]Webservice returns EndPointNotFoundException

I have a web service (LoginService) I am calling from another web service (AndroidService). 我有一个从另一个Web服务(AndroidService)调用的Web服务(LoginService)。 I have a simple method for testing the connection and it isn't working. 我有一种简单的方法来测试连接,但无法正常工作。

In LoginService I have a method called getStuff(string password) - it returns a string in JSON. 在LoginService中,我有一个名为getStuff(string password)的方法-它以JSON返回字符串。 When I access it via browser directly, at http://localhost/LoginService/LoginService.svc/getStuff/foo it works as it should be. 当我直接通过浏览器访问它时,可以在http://localhost/LoginService/LoginService.svc/getStuff/foo上正常运行。 When I try the same via the other web service, it fails with the exception in subject and an InnerException "The server returned 404 Not Found". 当我通过其他Web服务尝试相同操作时,它失败,主题发生异常,并显示InnerException“服务器返回404未找到”。

Here is the LoginService definition: 这是LoginService定义:

        [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "getStuff/{password}")]
        string getStuff(string password);

Here is the code from AndroidService: 这是来自AndroidService的代码:

    public string getStuff(string password)
    {
        string endpoint_address = "http://localhost/LoginService/LoginService.svc/";

        BasicHttpBinding binding = new BasicHttpBinding();
        EndpointAddress address = new EndpointAddress(endpoint_address);

        client = new LoginServiceClient(binding, address);
        return client.getStuff(password);
    }

And the AndroidService definition: 和AndroidService定义:

    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "getStuff/{password}")]
    string getStuff(string password);

Here is the full exception: 这是完整的例外:

Request Error
The server encountered an error processing the request. The exception message is 'There was no endpoint listening at http://localhost/LoginService/LoginService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.'. See server logs for more details. The exception stack trace is:

Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at AndroidServiceSpace.LoginServiceReference.ILoginService.getStuff(String password) at AndroidServiceSpace.LoginServiceReference.LoginServiceClient.getStuff(String password) in C:\AndroidServiceUUS\trunk\services\AndroidService\AndroidService\Service References\LoginServiceReference\Reference.cs:line 264 at AndroidServiceSpace.AndroidService.getStuff(String password) in C:\AndroidServiceUUS\trunk\services\AndroidService\AndroidService\AndroidService.svc.cs:line 77 at SyncInvokegetStuff(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

My web.config: 我的web.config:

<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<system.web>
  <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
  <bindings >
      <webHttpBinding>
          <binding name="BasicHttpBinding_UserService" maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647">
              <security mode="None" />
          </binding>
      </webHttpBinding>
  </bindings>      
     <client>
      <endpoint address="http://localhost/LoginService/LoginService.svc" binding="webHttpBinding"
          bindingConfiguration="BasicHttpBinding_UserService" contract="LoginServiceReference.ILoginService" />
  </client>      
<services>
  <service behaviorConfiguration="AndroidBehaviour" name="AndroidServiceSpace.AndroidService">
    <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
      contract="AndroidServiceSpace.IAndroidService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="AndroidBehaviour">
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

Moved LoginService to remove server to get Fiddler requests: 移动LoginService删除服务器以获取Fiddler请求:

#   Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
4   502 HTTP    10.0.4.12:50271 /AndroidService.svc/getStuff/ggnore 512     text/html; charset=UTF-8    chrome:4132         
5   502 HTTP    10.0.4.12:50271 /favicon.ico    512     text/html; charset=UTF-8    chrome:4132         
6   400 HTTP    localhost:50271 /AndroidService.svc/getStuff/ggnore 4 565   private     text/html   chrome:4132         
7   404 HTTP    localhost:50271 /favicon.ico    2 310   private     text/html; charset=utf-8    chrome:4132         
8   200 HTTP    Tunnel to   clients4.google.com:443 0           chrome:4132         
9   404 HTTP    maker.server    /LoginService/LoginService.svc/$metadata    1 565   private     text/html; charset=UTF-8    vwdexpress:5772         
10  200 HTTP    maker.server    /LoginService/LoginService.svc  2 790   private     text/html; charset=UTF-8    vwdexpress:5772         
11  200 HTTP    maker.server    /LoginService/LoginService.svc/mex  10 195  private     application/soap+xml; charset=utf-8 vwdexpress:5772         
12  404 HTTP    maker.server    /LoginService/LoginService.svc  1 565   private     text/html; charset=UTF-8    vwdexpress:5772         
13  200 HTTP    maker.server    /LoginService/LoginService.svc?disco    289 private     text/xml; charset=UTF-8 vwdexpress:5772         
14  200 HTTP    maker.server    /LoginService/LoginService.svc?wsdl 3 902   private     text/xml; charset=UTF-8 vwdexpress:5772         
15  200 HTTP    maker.server    /LoginService/LoginService.svc?xsd=xsd0 1 969   private     text/xml; charset=UTF-8 vwdexpress:5772         
16  200 HTTP    maker.server    /LoginService/LoginService.svc?xsd=xsd2 1 521   private     text/xml; charset=UTF-8 vwdexpress:5772         
17  200 HTTP    maker.server    /LoginService/LoginService.svc?xsd=xsd1 2 273   private     text/xml; charset=UTF-8 vwdexpress:5772         
18  200 HTTP    localhost:50271 /   2 756       text/html; charset=utf-8    chrome:4132         
19  404 HTTP    localhost:50271 /favicon.ico    2 310   private     text/html; charset=utf-8    chrome:4132         
20  400 HTTP    localhost:50271 /AndroidService.svc/getStuff/ggnore 4 565   private     text/html   chrome:4132         
21  404 HTTP    localhost:50271 /favicon.ico    2 310   private     text/html; charset=utf-8    chrome:4132         

Shown with a similar scenarios as yours: 以与您类似的场景显示:

LoginService: LoginService:

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,UriTemplate = "getStuff/{password}")]
string getStuff(string password);

AndroidService: AndroidService:

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,UriTemplate = "getStuff/{password}")]
string getStuff(string password);

Now my LoginService implementation: 现在,我的LoginService实现:

public string getStuff(string password)
{
    if ( password == "test")
          return "Success";
    else
          return "Failure";
}

Now my AndroidService implementation: 现在我的AndroidService实现:

public string getStuff(string password)
{
    // NOTE: Below 2 lines to acccess the login service via SOAP 
    // assuming that you have added a service reference to your project and added the needed config entries in you androidservice config file
    LoginServiceClient client = new LoginServiceClient(binding, address);
    return client.getStuff(password);

     // NOTE: Below code to access it RESTfully 
     string responseMessage = null;
     var request = WebRequest.Create("http://localhost/LoginService/LoginService.svc/getStuff/" + password) as HttpWebRequest;
    if (request != null)
    {
        request.ContentType = "application/json";      
        request.Method = "GET";
        var response = request.GetResponse() as HttpWebResponse;
                if(response.StatusCode == HttpStatusCode.OK)
                {
                    Stream responseStream = response.GetResponseStream();
                    if (responseStream != null)
                    {
                        var reader = new StreamReader(responseStream);

                        responseMessage = reader.ReadToEnd();                        
                    }
                }
                else
                {
                    responseMessage = response.StatusDescription;
                }
    }
    if (responseMessage == "Success")
    {
        return "Success";
    }
    else
    {
        return "Failure";
    }
}

Now from Fiddler i perform the below request (shown in Raw) 现在从Fiddler我执行以下请求(如Raw中所示)

GET http://localhost:50271/AndroidService.svc/getStuff/ggnore HTTP/1.1
Host: localhost
Content-Type: application/json

Web.config as shown : Web.config如下所示:

<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<system.web>
  <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
  <bindings >
      <webHttpBinding>
          <binding maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647">
              <security mode="None" />
          </binding>
      </webHttpBinding>
      <basicHttpBinding>
           <binding name="BasicHttpBinding_ILoginService" 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>
  <client>
        <endpoint address="http://maker.server/LoginService/LoginService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILoginService"
    contract="ILoginService" name="BasicHttpBinding_ILoginService" />
  </client>             
<services>
  <service behaviorConfiguration="AndroidBehaviour" name="AndroidServiceSpace.AndroidService">
    <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
      contract="AndroidServiceSpace.IAndroidService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="AndroidBehaviour">
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

NOTE: I am assuming that your LoginService is hosted as a seperate RESTful service and hence accessing it using the WebRequestClass. 注意:我假设您的LoginService作为单独的RESTful服务托管,因此使用WebRequestClass访问它。 If the LoginService is in the same project then define a service element for the LoginService similar to AndroidService and that should be enough. 如果LoginService在同一项目中,则为LoginService定义一个类似于AndroidService的服务元素,这样就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM