我有一个.asmx webservice,适用于我的Android客户端。 现在我正在尝试迁移到WCF但尚未成功。
我的配置如下:
<system.serviceModel>
<services>
<service name="myTimeMvc.Webservice.MyTimeService" behaviorConfiguration="returnFaults">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint binding="customBinding" bindingConfiguration="MyCustomHttpBinding" contract="myTimeMvc.Webservice.IMyTimeService" />
</service>
</services>
<bindings>
<customBinding>
<binding name="MyCustomHttpBinding">
<textMessageEncoding messageVersion="Soap12" />
<context protectionLevel ="None"/>
<httpTransport transferMode ="Buffered" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
我已经尝试了很多配置。实际上不应该默认设置满足我的需求。默认值是使用SOAP的basicHttpBinding,对吗?
我的合同如下:
[ServiceContract(Namespace = Constants.Namespace)]
public interface IMyTimeService
{
[OperationContract]
UserData getUserByEmail(String mail);
...
Constants.Namespace具有以下值:
public class Constants
{
// Ensures consistency in the namespace declarations across services
public const string Namespace = "http://timemanagement.mxp/";
}
我的android端看起来像:
final String soap_action = soap_action_getUserByEmail;
SoapObject request = new SoapObject(SOAP_NAMESPACE, soap_action);
request.addProperty("mail", email);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_NAMESPACE + soap_action, envelope);
User usrNew = new User();
SoapObject result = (SoapObject) envelope.bodyIn;
Adroid方面的值是:
static final String URL = "http://192.168.1.5/myTime/Webservice/MyTimeService.svc";
static final String SOAP_NAMESPACE = "http://timemanagement.mxp/";
// Users
public final static String soap_action_addUser = "addUser";
public static final String soap_action_getUsers = "getUsers";
public static final String soap_action_getUserByEmail = "getUserByEmail";
现在我收到以下错误: ode:s:Sender,Reason:由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action''的消息。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的约束(包括安全要求,例如邮件,传输,无)。
在wireshark中看不到任何问题。
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope"><v:Header /><v:Body><getUserByEmail xmlns="http://timemanagement.mxp/" id="o0" c:root="1"><mail i:type="d:string">omnia.cyano@gmail.com</mail></getUserByEmail></v:Body></v:Envelope>
任何人都可以帮助我吗?
干杯, 斯蒂芬
答案 0 :(得分:0)
[ServiceContract(Namespace = Constants.Namespace)]
public interface IMyTimeService
{
[OperationContract(Action = Constants.Namespace+"getUserByEmail")]
UserData getUserByEmail(String mail);
...
这解决了这个问题。