4

このサービスを作成しました (WCF、Azure を使用):

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Service1 : IPMPService
{
    public int Dummy()
    {
        return 0;
    }
}

IPMPService の場所:

[ServiceContract]
public interface IPMPService
{
    [WebGet()]
    [OperationContract]
    int Dummy();
}

そして、私のAndroidアプリでそれを消費しようとしました:
最初の試み:

String METHOD_NAME = "DummyRequest";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://tyty.cloudapp.net/Service1.svc";
String SOAP_ACTION = "http://tyty.cloudapp.net/Service1.svc/Dummy";

String res = "";
try {
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.call(SOAP_ACTION, envelope);
    SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
    // to get the data
    String resultData = result.toString();
    res = resultData;
    // 0 is the first object of data
    } catch (Exception e) {
        res = e.getMessage();
    }   

結果: SoapFault - faultcode: 'a:ActionNotSupported' faultstring: 'Action 'http://tyty.cloudapp.net/Service1.svc/Dummy' を含むメッセージは、EndpointDispatcher での ContractFilter の不一致により、受信側で処理できません. これは、コントラクトの不一致 (送信者と受信者の間のアクションの不一致) または送信者と受信者の間のバインディング/セキュリティの不一致が原因である可能性があります。送信者と受信者が同じコントラクトと同じバインディング (メッセージ、トランスポート、なしなどのセキュリティ要件を含む) を持っていることを確認してください。faultactor: 'null' 詳細: null

2回目の試行(ここから取得):

String SERVER_HOST = "http://tyty.cloudapp.net";
int SERVER_PORT = 8080;
String URL1 = "/Service1.svc/Dummy";
String keywords = null;
HttpEntity entity = null;
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(URL1);
try {
HttpResponse response = client.execute(target, get);
entity = response.getEntity();
keywords = EntityUtils.toString(entity);
} catch (Exception e) {
e.printStackTrace();
   } finally {
if (entity != null)
        try {
        entity.consumeContent();
    } catch (IOException e) {
  }
}  

結果: java.net.UnknownHostException: ホスト "http://tyty.cloudapp.net" を解決できません: ホスト名に関連付けられたアドレスがありません

また、c# で (動作する) クライアントを作成しました。その App.config は次のとおりです。

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IPMPService" 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://tyty.cloudapp.net/Service1.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPMPService"
          contract="IPMPService" name="BasicHttpBinding_IPMPService" />
    </client>
  </system.serviceModel>
</configuration>

前述のとおり、Android での試行は両方とも失敗しました。誰かが私が間違っていることと、それを正しく行う方法を教えてもらえますか?
ありがとう。

4

2 に答える 2

8

あなたの最初の試みはかなり近いです。必要な修正は2つだけです。

String METHOD_NAME = "Dummy";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://tyty.cloudapp.net/Service1.svc";
String SOAP_ACTION = "http://tempuri.org/IPMPService/Dummy";

String res = "";
try {
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.call(SOAP_ACTION, envelope);
    SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
    // to get the data
    String resultData = result.toString();
    res = resultData;
    // 0 is the first object of data
} catch (Exception e) {
    res = e.getMessage();
}   

最初のものはメソッド名です:それはDummy(の代わりにDummyRequest)それだけです。2番目はSOAPアクションです:それはhttp://tempuri.org/IPMPService/Dummyです。

どちらもWSDLから派生できます。操作は次のように定義されます。

<wsdl:operation name="Dummy">
    <wsdl:input wsaw:Action="http://tempuri.org/IPMPService/Dummy" message="tns:IPMPService_Dummy_InputMessage"/>
    <wsdl:output wsaw:Action="http://tempuri.org/IPMPService/DummyResponse" message="tns:IPMPService_Dummy_OutputMessage"/>
</wsdl:operation>

次にIPMPService_Dummy_InputMessageメッセージタイプを見ると、要素は次のように呼び出されDummyます。

<wsdl:message name="IPMPService_Dummy_InputMessage">
    <wsdl:part name="parameters" element="tns:Dummy"/>
</wsdl:message>

そして、SOAPアクションはここにあります:

<wsdl:operation name="Dummy">
    <soap:operation soapAction="http://tempuri.org/IPMPService/Dummy" style="document"/>
    ...
于 2012-05-27T09:03:45.650 に答える
0
public class RESTConnection extends Global 
{


    Global objglobal=Global.getInstance();

    private static String SERVICE_URI = "your service path";

    public JSONObject GetCashierLogin(String UserName, String Password)
    {
        new ArrayList<String>();  

        JSONObject jObj = null;  
        try 
        {

            SERVICE_URI=objglobal.getConnectionString();
            DefaultHttpClient httpClient = new DefaultHttpClient(); 
            HttpGet request = new HttpGet(SERVICE_URI+ "/LoginByUserIdAndPassword?Username=" + UserName + "&password=" + Password + "");
            request.setHeader("Accept", "application/json");
            request.setHeader("Content-type", "application/json");
            HttpResponse response = httpClient.execute(request);
            HttpEntity responseEntity = response.getEntity();
            String bufferLogin = EntityUtils.toString(responseEntity, HTTP.UTF_8);
            JSONArray jsonArray = new JSONArray(bufferLogin);

            if (jsonArray != null)
            {
                for (int i = 0; i < jsonArray.length(); i++)
                {
                    jObj=(JSONObject) jsonArray.get(i);

                }
            }

        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        return jObj;
    }
于 2013-06-14T13:44:38.413 に答える