Below is my code:
BasicHttpBinding basicHttpBinding = null;
EndpointAddress endpointAddress = null;
ChannelFactory<RtServiceImpl> factory = null;
RtServiceImpl serviceProxy = null;
try
{
basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
endpointAddress = new EndpointAddress(new Uri("https://webserviceurl"));
factory = new ChannelFactory<RtServiceImpl>(basicHttpBinding, endpointAddress);
factory.Credentials.UserName.UserName = "usrn";
factory.Credentials.UserName.Password = "passw";
serviceProxy = factory.CreateChannel();
using (var scope = new OperationContextScope((IContextChannel)serviceProxy))
{
var result = serviceProxy.getMethodAsync("xx", 0, 10).Result;
}
factory.Close();
((ICommunicationObject)serviceProxy).Close();
}
catch (MessageSecurityException ex)
{
throw;
}
catch (Exception ex)
{
throw;
}
When I call getMethodAsync
, it throws an exception:
An error occurred while serializing the body of the message: "no temporary class could be generated (result=1).Error CS0012: type "system.object" is defined in an unreferenced assembly.References to the assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" must be added.Error CS0012: type "system.nullable1 " is defined in an unreferenced assembly.References to the assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" must be added. Error CS0012: type "system.datetime" is defined in an unreferenced assembly.References to the assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" must be added. Error CS0030: cannot convert type "system.nullable1" to "system.datetime"
defination of proxy class:
[System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(TrainBean))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(ExamInfoBean))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(TraincMsBean))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(StudyInfoBean))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(TeacherLessonBean))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(TeacherBean))]
[return: System.ServiceModel.MessageParameterAttribute(Name="getTCTeacherBeanReturn")]
System.Threading.Tasks.Task<TeacherBean[]> getTCTeacherBeanAsync(string token, int startInex, int endInex);
public System.Threading.Tasks.Task<TeacherBean[]> getTCTeacherBeanAsync(string token, int startInex, int endInex)
{
return base.Channel.getTCTeacherBeanAsync(token, startInex, endInex);
}
netcoreapp2.0
ornet47
? Share us the defination for generatedgetMethodAsync
. Try to add<Reference Include="netstandard" />
in your.csproj
. Does this issue happen on this specific method or all service method? – Edward