【问题标题】:Port .asmx webservice to WCF for Android client将 .asmx webservice 移植到 WCF for Android 客户端
【发布时间】:2014-01-01 17:24:38
【问题描述】:

我有一个适用于我的 android 客户端的 .asmx 网络服务。 目前我正在尝试迁移到 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>

我已经尝试了很多配置。实际上,默认设置不应该满足我的需求。默认是basicHttpBinding with SOAP,对吧?

我的合同如下:

 [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/";
}

我的安卓端是这样的:

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,原因:由于 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>

谁能帮我解决这个问题?

干杯, 斯蒂芬

【问题讨论】:

  • SOAP_NAMESPACEsoap_action 的值是多少?此外,ServiceContract 上的命名空间看起来像一个 .NET 命名空间 - 我相信它应该是一个 XML 命名空间(如 http://tempuri.org/)。
  • 嗨,我在命名空间上玩了很多,这与我在 Android 中使用的相同。我会用这些信息更新我的帖子。

标签: android wcf wcf-binding ksoap2 android-ksoap2


【解决方案1】:
 [ServiceContract(Namespace = Constants.Namespace)]
public interface IMyTimeService
{
    [OperationContract(Action = Constants.Namespace+"getUserByEmail")]
    UserData getUserByEmail(String mail);

...

这解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多