Soap API 调用无法正常工作/找不到方法

问题描述 投票:0回答:0

我正在尝试调用 soap api。我必须 wsdl 文件并使用 svcutil 创建一个名为“PublicPortalServiceJSONPortTypeClient”的代理类。我已经按照微软文档使用 svcutil 进行调用,但我似乎无法让它工作。

我正在使用 dotnet framework 6 cli 这个项目正在使用控制台应用程序模板

错误:

System.NotSupportedException: Specified method is not supported.    at System.ServiceModel.MessageSecurityOverHttp.CreateSecurityBindingElement(Boolean isSecureTransportMode, Boolean isReliableSession, MessageSecurityVersion version)    at System.ServiceModel.WSHttpSecurity.CreateMessageSecurity(Boolean isReliableSessionEnabled, MessageSecurityVersion version)    at System.ServiceModel.WSHttpBinding.CreateMessageSecurity()    at System.ServiceModel.WSHttpBindingBase.CreateBindingElements()    at System.ServiceModel.WSHttpBinding.CreateBindingElements() cd25037@MacBook-Air-(2) PowerschoolAPI % dotnet run /Users/cd25037/dev/git/cs/PowerschoolAPI/Program.cs(4,7): warning CS0105: The using directive for 'Sys olAPI.csproj] System.NotSupportedException: Specified method is not supported.    at System.ServiceModel.MessageSecurityOverHttp.CreateSecurityBindingElement(Boolean isSecureTranspo    at System.ServiceModel.WSHttpSecurity.CreateMessageSecurity(Boolean isReliableSessionEnabled, Messa    at System.ServiceModel.WSHttpBinding.CreateMessageSecurity()    at System.ServiceModel.WSHttpBindingBase.CreateBindingElements()    at System.ServiceModel.WSHttpBinding.CreateBindingElements() cd25037@MacBook-Air-(2) PowerschoolAPI % dotnet run System.NotSupportedException: Specified method is not supported.    at System.ServiceModel.MessageSecurityOverHttp.CreateSecurityBindingElement(Boolean isSecureTranspo    at System.ServiceModel.WSHttpSecurity.CreateMessageSecurity(Boolean isReliableSessionEnabled, Messa    at System.ServiceModel.WSHttpBinding.CreateMessageSecurity() cd25037@MacBook-Air-(2) PowerschoolAPI % dotnet run System.NotSupportedException: Specified method is not supported.    at System.ServiceModel.MessageSecurityOverHttp.CreateSecurityBindingElement(Boolean isSecureTranspo    at System.ServiceModel.WSHttpSecurity.CreateMessageSecurity(Boolean isReliableSessionEnabled, Messa    at System.ServiceModel.WSHttpBinding.CreateMessageSecurity()    at System.ServiceModel.WSHttpBindingBase.CreateBindingElements()    at System.ServiceModel.WSHttpBinding.CreateBindingElements()    at System.ServiceModel.Channels.Binding.EnsureInvariants(String contractName)    at System.ServiceModel.Description.ServiceEndpoint.EnsureInvariants()    at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEn    at System.ServiceModel.ChannelFactory.CreateFactory()    at System.ServiceModel.ChannelFactory.OnOpening()    at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.O    at System.ServiceModel.Channels.CommunicationObject.OpenAsyncInternal(TimeSpan timeout)    at System.Runtime.TaskHelpers.WaitForCompletion(Task task)    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)    at System.ServiceModel.ClientBase
1.System.ServiceModel.ICommunicationObject.Open(TimeSpan超时) 在 System.ServiceModel.ClientBase
1.Open()    at Program.<Main>$(String[] args) in /Users/cd25037/dev/git/cs/PowerschoolAPI/Program.cs:line 30 

代码:

using ServiceReference;
using System.ServiceModel;

// Create the binding.
WSHttpBinding myBinding = new WSHttpBinding();
myBinding.Security.Mode = SecurityMode.TransportWithMessageCredential;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Digest;

// Create the endpoint address. Note that the machine name
// must match the subject or DNS field of the X.509 certificate
// used to authenticate the service.
EndpointAddress ea = new EndpointAddress("https://fccps.powerschool.com:8443/pearson-rest/services/PublicPortalServiceJSON.PublicPortalServiceJSONHttpsSoap11Endpoint/");

// Create the client. The code for the calculator
// client is not shown here. See the sample applications
// for examples of the calculator code.
PublicPortalServiceJSONPortTypeClient cc = new PublicPortalServiceJSONPortTypeClient(myBinding, ea);
// The client must provide a user name and password. The code
// to return the user name and password is not shown here. Use
// a database to store the user name and passwords, or use the
// ASP.NET Membership provider database.
cc.ClientCredentials.UserName.UserName = "pearson";
cc.ClientCredentials.UserName.Password = "m0bApP5";
try
{
    // Begin using the client.
    // cc.Abort();
    // await cc.OpenAsync();
    // await cc.loginAsync("","",0);
    cc.Open();
    var login = await cc.loginToPublicPortalAsync("<redacted>", "<redacted>");
    

    // cc.Close();
}
catch(Exception e){
     Console.WriteLine(e);
}

WSDL 来源:https://docs.google.com/document/d/1uN2PJvS7Iz8XOpJDeBivxM4Wv3fI39jq-8G_No8LEa8/edit?usp=sharing

我已经尝试了代理类中包含的所有函数,但没有一个起作用,包括 cc.open();。我已将 wsdl 源中找到的所有 soap 端点用于端点 uri。

c# .net soap wsdl
© www.soinside.com 2019 - 2024. All rights reserved.