我创建了这项服务(使用WCF、Azure):
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Service1 : IPMPService
{
public int Dummy()
{
return 0;
}
}
IPMP服务是:
[ServiceContract]
public interface IPMPService
{
[WebGet()]
[OperationContract]
int Dummy();
}
And attempted to consume it in my android app:
1st attempt:
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 - 错误代码: a: ActionNotsupported faultstries: a: ActionNotsupported: the message with Action http://tyty.cloudappp.net/Servicice1.svc/Dummy 无法在接收器上处理电文,因为终端Dispatcher的合同Filter不匹配。这可能是因为合同不匹配(发件人和接收人之间有片断动作),也可能是因为发件人和接收人之间有约束性/安全不匹配。检查发件人和接收人有相同的合同和相同的约束性(包括安全要求,如电文、运输、无)。
第二次尝试(取自"http://romenlaw.blogspot.com/2008/08/pot-web-services- from-android.html" rel=“不跟随 noreferrer">这里):
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. unnownHostExpusion: 无法解析主机“ 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>
As mentioned, both attempts in Android failed. Can anyone please tell me what I m doing wrong, and how to do it right?
Thanks.