本文介绍了xamarin.forms 中 iOS 单声道错误的代理类覆盖方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是代理类的新手.我认为 Visual Studio 只是处理了它们,再也没有想过它们.现在,我遇到了问题.

I am new to proxy classes. I thought visual studio just handled them and never thought about them again. Now, I am having problems.

在 iOS 上运行我的 Xamarin.Forms 应用程序时,它在调用我的 WCF 时抛出此错误:

When running my Xamarin.Forms App on iOS, it throws this error when calling my WCF:

MonoTouch 不支持动态代理代码生成.覆盖这种方法...(等)

所以在代理代码中,我创建了这个方法:

So in the proxy code, I created this method:

protected override IService1 CreateChannel()
{
    return new Service1ClientChannel(this);
}

但是返回的 Service1ClientChannel 无法识别.我为返回对象放了什么?由于我是代理类的新手,如果您无法回答这个问题,那么学习自己创建/编辑它们的好资源是什么?提前致谢.

But the return Service1ClientChannel is not recognized. What do I put for the return object? Since I am new to proxy classes, if you can't answer that question, then what is a good resource to learn about creating/editing them myself? Thanks in advance.

以下是某些上下文的更多代理代码:

Below is more of the proxy code for some context:

public partial class Service1Client : System.ServiceModel.ClientBase<IService1>, IService1
{

public Service1Client()
{
}

protected override IService1 CreateChannel()
{
    return new Service1ClientChannel(this);
}

public Service1Client(string endpointConfigurationName) :
        base(endpointConfigurationName)
{
}

public Service1Client(string endpointConfigurationName, string remoteAddress) :
        base(endpointConfigurationName, remoteAddress)
{
}

public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
        base(endpointConfigurationName, remoteAddress)
{
}

public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
        base(binding, remoteAddress)
{
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
CheckIfUserExistsResponse IService1.CheckIfUserExists(CheckIfUserExistsRequest request)
{
    return base.Channel.CheckIfUserExists(request);
}

public int CheckIfUserExists(string userName, string password)
{
    CheckIfUserExistsRequest inValue = new CheckIfUserExistsRequest();
    inValue.userName = userName;
    inValue.password = password;
    CheckIfUserExistsResponse retVal = ((IService1)(this)).CheckIfUserExists(inValue);
    return retVal.CheckIfUserExistsResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult IService1.BeginCheckIfUserExists(CheckIfUserExistsRequest request, System.AsyncCallback callback, object asyncState)
{
    return base.Channel.BeginCheckIfUserExists(request, callback, asyncState);
}

public System.IAsyncResult BeginCheckIfUserExists(string userName, string password, System.AsyncCallback callback, object asyncState)
{
    CheckIfUserExistsRequest inValue = new CheckIfUserExistsRequest();
    inValue.userName = userName;
    inValue.password = password;
    return ((IService1)(this)).BeginCheckIfUserExists(inValue, callback, asyncState);
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
CheckIfUserExistsResponse IService1.EndCheckIfUserExists(System.IAsyncResult result)
{
    return base.Channel.EndCheckIfUserExists(result);
}

public int EndCheckIfUserExists(System.IAsyncResult result)
{
    CheckIfUserExistsResponse retVal = ((IService1)(this)).EndCheckIfUserExists(result);
    return retVal.CheckIfUserExistsResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
CheckIfUserNameExistsResponse IService1.CheckIfUserNameExists(CheckIfUserNameExistsRequest request)
{
    return base.Channel.CheckIfUserNameExists(request);
}

public int CheckIfUserNameExists(string userName)
{
    CheckIfUserNameExistsRequest inValue = new CheckIfUserNameExistsRequest();
    inValue.userName = userName;
    CheckIfUserNameExistsResponse retVal = ((IService1)(this)).CheckIfUserNameExists(inValue);
    return retVal.CheckIfUserNameExistsResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult IService1.BeginCheckIfUserNameExists(CheckIfUserNameExistsRequest request, System.AsyncCallback callback, object asyncState)
{
    return base.Channel.BeginCheckIfUserNameExists(request, callback, asyncState);
}

public System.IAsyncResult BeginCheckIfUserNameExists(string userName, System.AsyncCallback callback, object asyncState)
{
    CheckIfUserNameExistsRequest inValue = new CheckIfUserNameExistsRequest();
    inValue.userName = userName;
    return ((IService1)(this)).BeginCheckIfUserNameExists(inValue, callback, asyncState);
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
CheckIfUserNameExistsResponse IService1.EndCheckIfUserNameExists(System.IAsyncResult result)
{
    return base.Channel.EndCheckIfUserNameExists(result);
}

public int EndCheckIfUserNameExists(System.IAsyncResult result)
{
    CheckIfUserNameExistsResponse retVal = ((IService1)(this)).EndCheckIfUserNameExists(result);
    return retVal.CheckIfUserNameExistsResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
CreateUserResponse IService1.CreateUser(CreateUserRequest request)
{
    return base.Channel.CreateUser(request);
}

public int CreateUser(string userName, string password)
{
    CreateUserRequest inValue = new CreateUserRequest();
    inValue.userName = userName;
    inValue.password = password;
    CreateUserResponse retVal = ((IService1)(this)).CreateUser(inValue);
    return retVal.CreateUserResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult IService1.BeginCreateUser(CreateUserRequest request, System.AsyncCallback callback, object asyncState)
{
    return base.Channel.BeginCreateUser(request, callback, asyncState);
}

public System.IAsyncResult BeginCreateUser(string userName, string password, System.AsyncCallback callback, object asyncState)
{
    CreateUserRequest inValue = new CreateUserRequest();
    inValue.userName = userName;
    inValue.password = password;
    return ((IService1)(this)).BeginCreateUser(inValue, callback, asyncState);
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
CreateUserResponse IService1.EndCreateUser(System.IAsyncResult result)
{
    return base.Channel.EndCreateUser(result);
}

public int EndCreateUser(System.IAsyncResult result)
{
    CreateUserResponse retVal = ((IService1)(this)).EndCreateUser(result);
    return retVal.CreateUserResult;
}

public System.IO.Stream GetImageByteStream(int zipCode)
{
    return base.Channel.GetImageByteStream(zipCode);
}

public System.IAsyncResult BeginGetImageByteStream(int zipCode, System.AsyncCallback callback, object asyncState)
{
    return base.Channel.BeginGetImageByteStream(zipCode, callback, asyncState);
}

public System.IO.Stream EndGetImageByteStream(System.IAsyncResult result)
{
    return base.Channel.EndGetImageByteStream(result);
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
GetDsImageAndIDResponse IService1.GetDsImageAndID(GetDsImageAndIDRequest request)
{
    return base.Channel.GetDsImageAndID(request);
}

public System.Data.DataSet GetDsImageAndID(int zipCode)
{
    GetDsImageAndIDRequest inValue = new GetDsImageAndIDRequest();
    inValue.zipCode = zipCode;
    GetDsImageAndIDResponse retVal = ((IService1)(this)).GetDsImageAndID(inValue);
    return retVal.GetDsImageAndIDResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult IService1.BeginGetDsImageAndID(GetDsImageAndIDRequest request, System.AsyncCallback callback, object asyncState)
{
    return base.Channel.BeginGetDsImageAndID(request, callback, asyncState);
}

public System.IAsyncResult BeginGetDsImageAndID(int zipCode, System.AsyncCallback callback, object asyncState)
{
    GetDsImageAndIDRequest inValue = new GetDsImageAndIDRequest();
    inValue.zipCode = zipCode;
    return ((IService1)(this)).BeginGetDsImageAndID(inValue, callback, asyncState);
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
GetDsImageAndIDResponse IService1.EndGetDsImageAndID(System.IAsyncResult result)
{
    return base.Channel.EndGetDsImageAndID(result);
}

public System.Data.DataSet EndGetDsImageAndID(System.IAsyncResult result)
{
    GetDsImageAndIDResponse retVal = ((IService1)(this)).EndGetDsImageAndID(result);
    return retVal.GetDsImageAndIDResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
GetDsItemInfoResponse IService1.GetDsItemInfo(GetDsItemInfoRequest request)
{
    return base.Channel.GetDsItemInfo(request);
}

public System.Data.DataSet GetDsItemInfo(int itemID)
{
    GetDsItemInfoRequest inValue = new GetDsItemInfoRequest();
    inValue.itemID = itemID;
    GetDsItemInfoResponse retVal = ((IService1)(this)).GetDsItemInfo(inValue);
    return retVal.GetDsItemInfoResult;
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult IService1.BeginGetDsItemInfo(GetDsItemInfoRequest request, System.AsyncCallback callback, object asyncState)
{
    return base.Channel.BeginGetDsItemInfo(request, callback, asyncState);
}

public System.IAsyncResult BeginGetDsItemInfo(int itemID, System.AsyncCallback callback, object asyncState)
{
    GetDsItemInfoRequest inValue = new GetDsItemInfoRequest();
    inValue.itemID = itemID;
    return ((IService1)(this)).BeginGetDsItemInfo(inValue, callback, asyncState);
}

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
GetDsItemInfoResponse IService1.EndGetDsItemInfo(System.IAsyncResult result)
{
    return base.Channel.EndGetDsItemInfo(result);
}

public System.Data.DataSet EndGetDsItemInfo(System.IAsyncResult result)
{
    GetDsItemInfoResponse retVal = ((IService1)(this)).EndGetDsItemInfo(result);
    return retVal.GetDsItemInfoResult;
}

}

推荐答案

解决方案是自己定义Service1ClientChannel"类:

The solution was to define the "Service1ClientChannel" class myself:

private class Service1ClientChannel : ChannelBase<IService1>, IService1
{
    public Service1ClientChannel(System.ServiceModel.ClientBase<IService1> client) :
       base(client)
    {
    }

    public IAsyncResult BeginCheckIfUserExists(CheckIfUserExistsRequest request, AsyncCallback callback, object asyncState)
    {
        object[] _args = new object[1];
        _args[0] = request;
        return (IAsyncResult)base.BeginInvoke("CheckIfUserExists", _args, callback, asyncState);
    }

    public IAsyncResult BeginCheckIfUserNameExists(CheckIfUserNameExistsRequest request, AsyncCallback callback, object asyncState)
    {
        object[] _args = new object[1];
        _args[0] = request;
        return (IAsyncResult)base.BeginInvoke("CheckIfUserNameExists", _args, callback, asyncState);
    }

    public IAsyncResult BeginCreateUser(CreateUserRequest request, AsyncCallback callback, object asyncState)
    {
        object[] _args = new object[1];
        _args[0] = request;
        return (IAsyncResult)base.BeginInvoke("CreateUser", _args, callback, asyncState);
    }

    public IAsyncResult BeginGetDsImageAndID(GetDsImageAndIDRequest request, AsyncCallback callback, object asyncState)
    {
        object[] _args = new object[1];
        _args[0] = request;
        return (IAsyncResult)base.BeginInvoke("GetDsImageAndID", _args, callback, asyncState);
    }

    public IAsyncResult BeginGetDsItemInfo(GetDsItemInfoRequest request, AsyncCallback callback, object asyncState)
    {
        object[] _args = new object[1];
        _args[0] = request;
        return (IAsyncResult)base.BeginInvoke("GetDsItemInfo", _args, callback, asyncState);
    }

    public IAsyncResult BeginGetImageByteStream(int zipCode, AsyncCallback callback, object asyncState)
    {
        throw new NotImplementedException();
    }

    public CheckIfUserExistsResponse CheckIfUserExists(CheckIfUserExistsRequest request)
    {
        throw new NotImplementedException();
    }

    public CheckIfUserNameExistsResponse CheckIfUserNameExists(CheckIfUserNameExistsRequest request)
    {
        throw new NotImplementedException();
    }

    public CreateUserResponse CreateUser(CreateUserRequest request)
    {
        throw new NotImplementedException();

    }

    public CheckIfUserExistsResponse EndCheckIfUserExists(IAsyncResult result)
    {
        throw new NotImplementedException();
    }

    public CheckIfUserNameExistsResponse EndCheckIfUserNameExists(IAsyncResult result)
    {
        object[] _args = new object[0];
        return (CheckIfUserNameExistsResponse)base.EndInvoke("CheckIfUserNameExists", _args, result);
        //return Service1Client.
    }

    public CreateUserResponse EndCreateUser(IAsyncResult result)
    {
        object[] _args = new object[0];
        return (CreateUserResponse)base.EndInvoke("CreateUser", _args, result);
    }

    public GetDsImageAndIDResponse EndGetDsImageAndID(IAsyncResult result)
    {
        object[] _args = new object[0];
        return (GetDsImageAndIDResponse)base.EndInvoke("GetDsImageAndID", _args, result);
    }

    public GetDsItemInfoResponse EndGetDsItemInfo(IAsyncResult result)
    {
        object[] _args = new object[0];
        return (GetDsItemInfoResponse)base.EndInvoke("GetDsItemInfo", _args, result);
    }

    public Stream EndGetImageByteStream(IAsyncResult result)
    {
        throw new NotImplementedException();
    }

    public GetDsImageAndIDResponse GetDsImageAndID(GetDsImageAndIDRequest request)
    {
        throw new NotImplementedException();
    }

    public GetDsItemInfoResponse GetDsItemInfo(GetDsItemInfoRequest request)
    {
        throw new NotImplementedException();
    }

    public Stream GetImageByteStream(int zipCode)
    {
        throw new NotImplementedException();
    }
}

这篇关于xamarin.forms 中 iOS 单声道错误的代理类覆盖方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:13