难以获得.Net Web服务来读取从Java客户端传递的参数 [英] Having difficulty getting .Net web service to read parameters passed from Java client

查看:66
本文介绍了难以获得.Net Web服务来读取从Java客户端传递的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,希望有人可以提供帮助。

我有一个非常简单的.net网络服务,我打算与Android通信。

在android端我正在使用kso​​ap2库。



没有传递任何参数,服务工作正常。

但是,当我尝试传递参数时,它就像.net端不接收它们,或者值被删除,转换为默认值或类似的东西。

当我构建一个.net应用程序来使用服务时,服务传递和处理参数就好了,但是.net包含了很多复杂的东西,所以我看不到最新情况。



我使用Wireshark将xml发送到服务并在下面提供。
来自.net应用程序的
XML。从服务中正确地接收,处理和返回此xml :(<符号替换为'lt')

lt V:Envelope

xmlns:i =http: //www.w3.org/2001/XMLSchema-instance

xmlns:d =http // www.w3.org.2001.XMLSchema

xmlns: c =http://schemas.xmlsoap.org/soap/encoding/

xmlns:v =http://shcema.xmlsoap.org/soap/envelope/>

lt v:Header />

lt v:Body>

lt n0:AddNumber id =o0c:root =1 xmlns:n0 =http://tempuri.org/>

lt num1 i:type =d:int>

3

lt / num1>

lt num2 i:type =d:int>

8

lt / num2>

lt n0:AddNumber>

/ v:Body>

lt / V:Envelope>







服务收到xml的下一个副本,但当我逐步执行服务中的代码时,num1和num2的值是0.

lt s:信封

xmlns :s =http://schemas.xmlsoap.org/soap/envelope/>

lt s:正文>

lt AddNumber xmlns =http:/ /tempuri.org/\">

lt num1>

8

lt / num1>

lt num2> ;

7

lt / num2>

lt / AddNumber>

lt s:Body>

lt / s:信封>



以下是Android服务的主要部分:

'@ Override

'protected Void doInBackground(Void ... arg0){

SOAP_ACTION = SOAP_ACTION +方法;

METHOD_NAME = METHOD_NAME +方法;



SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

request.addProperty(num1,3);

request.addProperty(num2,8);



envelo pe.setOutputSoapObject(request);



HttpTransportSE httpTransport = new HttpTransportSE(URL);

httpTransport.debug = true;



试试{

httpTransport.call(SOAP_ACTION,信封);

}

catch( HttpResponseException e){

// TODO自动生成的捕获块

e.printStackTrace();

}

catch(IOException e){

// TODO自动生成的捕获块

e.printStackTrace();

}

catch(XmlPullParserException e){

// TODO自动生成的捕获块

e.printStackTrace();

} / /发送请求



对象结果= null;

尝试{

result =(Object)envelope.getResponse();

}

catch(SoapFault e){

// TODO自动生成的catch块

e.printStackTrace();

}

catch(例外e){

e.printStackTrace() ;

}

response = result.toString();

返回null;



最后,该服务的web.config。

lt?xml version =1.0?>

lt配置>

lt system.diagnostics>

lt sources>

lt source name =System.ServiceModel.MessageLogging>

lt listeners>

lt add name =messagelistenertype =System.Diagnostics.XmlWriterTraceListener

initializeData =C:\ logsmyMessages.svclog> lt / add>

lt / listeners>

lt / source&g t;

lt / sources>

lt trace autoflush =true/>

lt /system.diagnostics>

lt system.web>

lt compilation debug =truestrict =falseexplicit =truetargetFramework =4.0/>

lt /system.web>

lt system.serviceModel>

lt diagnostics>

lt messageLogging logEntireMessage =truelogMalformedMessages =false logMessagesAtServiceLevel =true

logMessagesAtTransportLevel =falsemaxMessagesToLog =3000maxSizeOfMessageToLog =2000/>

lt / diagnostics>

lt services>

lt service name =CalculatorService.Service1behaviorConfiguration =CalculatorServiceBehavior>

lt endpoint address =binding =basicHttpBindingcontract = CalculatorService.IService1> lt / endpoint>

lt endpoint address =mexbinding =mexHttpBindingcontract =IMetadataExchange/>

lt host>

lt baseAddresses>

lt add baseAddress =http://72.198.31.100:8080 //>

lt / baseAddresses>

lt / host>

lt / service>

lt / services>

lt行为>

lt serviceBehaviors>

lt behavior name =CalculatorServiceBehavior>

lt serviceMetadata httpGetEnabled =true/>

lt / behavior>

lt / serviceBehaviors>

lt / behavior>

lt /system.serviceModel>



lt / configuration>



感谢您的帮助。

Hello, Hoping someone can provide some help.
I have a quite simple .net web service which I intend to communicate with an Android.
On the android side I'm using the ksoap2 library.

Without any parameters being passed, the service works fine.
However, when I try and pass parameters, its like the .net side doesn't recieve them, or the values are dropped, cast to default or something similar.
When I built a .net app to consume the service, parameters are passed and processed by the service just fine, but then .net wraps much of the complicated stuff so I don't see whats going on.

I've used Wireshark to get the xml sent to the service and its supplied below.
XML from .net app. This xml is recieved, processed and returned correctly from the service: (< symbol replaced with 'lt')
lt V:Envelope
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http//www.w3.org.2001.XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://shcema.xmlsoap.org/soap/envelope/">
lt v:Header/>
lt v:Body>
lt n0:AddNumber id="o0" c:root="1" xmlns:n0="http://tempuri.org/>
lt num1 i:type="d:int">
3
lt /num1>
lt num2 i:type="d:int">
8
lt /num2>
lt n0:AddNumber>
/v:Body>
lt /V:Envelope>



This next copy of xml is recieved by the service, but when I step thru the code in the service, the values for num1 and num2 are 0.
lt s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
lt s:Body>
lt AddNumber xmlns="http://tempuri.org/">
lt num1>
8
lt /num1>
lt num2>
7
lt /num2>
lt /AddNumber>
lt s:Body>
lt /s:Envelope>

Below is the main part of the Android service:
'@Override
'protected Void doInBackground(Void... arg0) {
SOAP_ACTION = SOAP_ACTION + method;
METHOD_NAME = METHOD_NAME + method;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
request.addProperty("num1", 3);
request.addProperty("num2", 8);

envelope.setOutputSoapObject(request);

HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;

try {
httpTransport.call(SOAP_ACTION, envelope);
}
catch (HttpResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //send request

Object result = null;
try {
result = (Object)envelope.getResponse();
}
catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
response = result.toString();
return null;

And lastly, the web.config of the service.
lt ?xml version="1.0"?>
lt configuration>
lt system.diagnostics>
lt sources>
lt source name="System.ServiceModel.MessageLogging">
lt listeners>
lt add name="messagelistener" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\logsmyMessages.svclog">lt /add>
lt /listeners>
lt /source>
lt /sources>
lt trace autoflush="true" />
lt /system.diagnostics>
lt system.web>
lt compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
lt /system.web>
lt system.serviceModel>
lt diagnostics>
lt messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/>
lt /diagnostics>
lt services>
lt service name="CalculatorService.Service1" behaviorConfiguration="CalculatorServiceBehavior">
lt endpoint address="" binding="basicHttpBinding" contract="CalculatorService.IService1">lt /endpoint>
lt endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
lt host>
lt baseAddresses>
lt add baseAddress="http://72.198.31.100:8080/" />
lt /baseAddresses>
lt /host>
lt /service>
lt /services>
lt behaviors>
lt serviceBehaviors>
lt behavior name="CalculatorServiceBehavior">
lt serviceMetadata httpGetEnabled="true"/>
lt /behavior>
lt /serviceBehaviors>
lt /behaviors>
lt /system.serviceModel>

lt /configuration>

Thanks for any help.

推荐答案

请参阅Peter Leow的文章: 在Android上处理输入和存储 [ ^ ]。
See Peter Leow's article: Handling Input and Storage on Android[^].


感谢Peter对所列文章的引用,它提供了解决方案。

在这种情况下,添加以下行代码。



envelope.dotNet = true;



Wireshark透露,有一点变化

之后的xml内容'AddNumber'标签(或特定方法标签)



读取失败的xml:id =o0c :root =1xmlns:n0 =http://tempuri.org/

而工作xml:xmlns =http://tempuri.org/id =o0c :root =1



看起来dotNet标志将内容格式更改为.net期望的内容。
Thanks Peter on the reference to the listed article, it provided the solution.
Which in this case was adding the following line of code.

envelope.dotNet = true;

Wireshark revealed that there was a slight change in the xml content right after
the 'AddNumber' tag (or particular method tag)

The failing xml read: id="o0" c:root="1" xmlns:n0="http://tempuri.org/
whereas the working xml: xmlns="http://tempuri.org/" id="o0" c:root="1"

It looks like the dotNet flag changes that content format to what .net expects.


If我可以想出如何编辑问题。 ANyway,请反转上面的xml示例。第一个例子是从Android发送的xml不起作用。



第二个xml示例是从.net客户端发送的。
If i could figure how to edit questions I would. ANyway, please reverse the xml examples above. The first example is the xml sent from Android that does not work.

The second xml example is send from a .net client which does work.

这篇关于难以获得.Net Web服务来读取从Java客户端传递的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆