强类型或无类型消息错误:Unity(WSDL)上的Web服务

时间:2018-06-29 08:50:08

标签: c# web-services unity3d exception wsdl

我正在尝试在Unity上使用Web服务。我使用svcutil制作了Web服务的代理类。代理类非常长,我将在此处发布我在C#脚本上调用的方法。

在我的代理课程中,我有:

public bool LoginClic(string szUserName, string szPassword)
{
    LoginClicRequest inValue = new LoginClicRequest();
    inValue.Body = new LoginClicRequestBody();
    inValue.Body.szUserName = szUserName;
    inValue.Body.szPassword = szPassword;
    LoginClicResponse retVal = ((UserServiceSoap)(this)).LoginClic(inValue);
    return retVal.Body.LoginClicResult;
}

我的C#脚本看起来像那样,并且当用户单击Unity上的Button时被激活

public class LoginButton : MonoBehaviour 
{

    public GameObject login;
    public GameObject password;

    private InputField loginField;
    private InputField passwordField;

    // Use this for initialization
    void Start ()
    {
        loginField = login.GetComponent<InputField>();
        passwordField = password.GetComponent<InputField>();
    }

    public void PressLogin()
    {
        string szLogin, szPassword;

        szLogin = loginField.text;
        szPassword = passwordField.text;

        UserServiceSoapClient user = new UserServiceSoapClient(new BasicHttpBinding(),
                                  new EndpointAddress("http://localhost/WebService/UserService.asmx"));

        if (user.LoginClic(szLogin, szPassword))
        {
            Debug.Log("Sucess");
        }
        else
        {
            Debug.Log("Failure");
        }
    }
}

问题是,当我使用此按钮时,出现一个异常:

InvalidOperationException: Operation 'LoginClicAsync' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message.
System.ServiceModel.Dispatcher.OperationFormatter.Validate (System.ServiceModel.Description.OperationDescription od, System.Boolean isRpc, 
System.Boolean isEncoded) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.Dispatcher.OperationFormatter..ctor (System.ServiceModel.Description.OperationDescription od, System.Boolean isRpc, 
System.Boolean isEncoded) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.Description.ContractDescription.PopulateClientOperation (System.ServiceModel.Dispatcher.ClientRuntime proxy, 
System.ServiceModel.Description.OperationDescription od, System.Boolean isCallback) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.Description.ContractDescription.FillClientOperations (System.ServiceModel.Dispatcher.ClientRuntime proxy, System.Boolean isCallback) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.Description.ContractDescription.CreateClientRuntime (System.Object callbackDispatchRuntime) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.Description.ServiceEndpoint.CreateClientRuntime (System.Object callbackDispatchRuntime) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.MonoInternal.ClientRuntimeChannel..ctor (System.ServiceModel.Description.ServiceEndpoint endpoint, 
System.ServiceModel.ChannelFactory channelFactory, 
System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.ChannelFactory`1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.ChannelFactory`1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address) (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.ChannelFactory`1[TChannel].CreateChannel () (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.ClientBase`1[TChannel].CreateChannel () (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.ClientBase`1[TChannel].get_InnerChannel () (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
System.ServiceModel.ClientBase`1[TChannel].get_Channel () (at <40d7d6933b0c4e6f97e3ac69c092efd6>:0)
UserServiceSoapClient.UserServiceSoap.LoginClic (LoginClicRequest request) (at Assets/Script/WebService/UserService.cs:238)
UserServiceSoapClient.LoginClic (System.String szUserName, System.String szPassword) (at Assets/Script/WebService/UserService.cs:247)
LoginButton.PressLogin () (at Assets/Script/Login/LoginButton.cs:32)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, 
UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, 
UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()

由于生成了代理类,我觉得我不应该碰它,所以我想知道我做过哪些不好的事情会导致这种情况?我的方法接受2个字符串作为参数并返回布尔值。

我不确定是否会非常有用,但这是WSDL中此方法的外观:

<s:element name="LoginClic">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="szUserName" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="szPassword" type="s:string"/>
        </s:sequence>
    </s:complexType>
</s:element>
<s:element name="LoginClicResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="LoginClicResult" type="s:boolean"/>
        </s:sequence>
    </s:complexType>
</s:element>

非常感谢您的帮助,祝您生活愉快。

编辑1:经过数小时的研究,我觉得我可能和这些人有同样的问题:https://github.com/dotnet/wcf/issues/1808,但他们也没有找到解决方法。

0 个答案:

没有答案