0

別の Web サービス (AndroidService) から呼び出している Web サービス (LoginService) があります。接続をテストする簡単な方法がありますが、機能していません。

LoginService には getStuff(string password) というメソッドがあります。JSON で文字列を返します。ブラウザから直接アクセスすると、http://localhost/LoginService/LoginService.svc/getStuff/fooで正常に動作します。他の Web サービスを介して同じことを試みると、件名の例外と InnerException "The server returned 404 Not Found" で失敗します。

LoginService の定義は次のとおりです。

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

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);
    }

そして AndroidService 定義:

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

完全な例外は次のとおりです。

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)

私の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>

Fiddler リクエストを取得するためにサーバーを削除するように LoginService を移動しました。

#   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         
4

1 に答える 1

1

あなたと同様のシナリオで示されています:

ログインサービス:

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

Android サービス:

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

今、私の LoginService 実装:

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

今私の 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";
    }
}

Fiddler から以下のリクエストを実行します (Raw で表示)

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

示されている 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>

注: LoginService は別の RESTful サービスとしてホストされているため、WebRequestClass を使用してアクセスすると想定しています。LoginService が同じプロジェクトにある場合は、AndroidService と同様の LoginService のサービス要素を定義します。これで十分です。

于 2012-05-09T11:46:24.733 に答える