问题
I am new to proxy classes. I thought visual studio just handled them and never thought about them again. Now, I am having problems.
When running my Xamarin.Forms App on iOS, it throws this error when calling my WCF:
MonoTouch does not support dynamic proxy code generation. Override this method...(etc)
So in the proxy code, I created this method:
protected override IService1 CreateChannel()
{
return new Service1ClientChannel(this);
}
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;
}
}
回答1:
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();
}
}
来源:https://stackoverflow.com/questions/51887706/proxy-class-override-method-for-ios-mono-error-in-xamarin-forms