0
votes

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);
    }
1
Can you please print the exception in english? You can't expect someone to read chinese (sorry if I'm wrong with that) lettershellow
@hellow,I'm sorry.I try to change it to be englishgouhan
Do you target your project to netcoreapp2.0 or net47? Share us the defination for generated getMethodAsync. Try to add <Reference Include="netstandard" /> in your .csproj. Does this issue happen on this specific method or all service method?Edward
project type is netcoreapp2.0,then netstandard reference is default include in this type project. I test calling it use webservice reference in netframework project,it works good.The defination for generated proxy class,please see the question's body.I will update it later,Thanks.gouhan

1 Answers

0
votes

Now,I use the http protocals to call the soap method.

 if (url.StartsWith("https"))
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        }
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Timeout = timeout;
        request.Method = "POST";
        request.KeepAlive = true;
        request.ContentType = "text/xml;charset=UTF-8";
        request.Headers.Set("SOAPAction", soapAction);
        try
        {
            using (Stream stream = request.GetRequestStream())
            {
                byte[] datas = Encoding.UTF8.GetBytes(soapXml);
                stream.Write(datas, 0, datas.Length);
                stream.Close();
            }
            var response = (HttpWebResponse)request.GetResponse();
            using (Stream stream = response.GetResponseStream())
            {
                if (stream != null)
                {
                    var reader = new StreamReader(stream);
                    return System.Web.HttpUtility.HtmlDecode(reader.ReadToEnd());
                }
            }
        }
        catch (Exception ex)
        {
        }
        return string.Empty;

if the server is http,it returns ok.when the server is https,though I added some code here:

if (url.StartsWith("https"))
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        }

it throw exception: Request aborted: failed to create SSL/TLS security channel. but it works well in netframework's project.