英文:
Creating a soap endpoint from WSDL in .net
问题
I am trying to create a SOAP web service that will be consumed by another company. This company expects to give the data in a certain way, hence I have created a WSDL to reflect that.
我正在尝试创建一个SOAP Web服务,将被另一家公司使用。该公司期望以特定的方式提供数据,因此我已创建了一个WSDL以反映这一点。
I don't need to auto-generate the service from the WSDL, but if I could that would be nice.
我不需要从WSDL自动生成服务,但如果可以的话,那会很好。
I am just trying to create a service that will consume data, like the WSDL suggests. I am using .net core 6.
我只是想创建一个能够消费数据的服务,就像WSDL所建议的那样。我正在使用.NET Core 6。
I have tried using serviceStack And I built out the envelope/header/body classes, such that it performs as desired. But it seems a little wonky because I am unable to query the WSDL.
我尝试使用ServiceStack,并构建了信封/头部/主体类,以使其按预期运行。但似乎有点问题,因为我无法查询WSDL。
If my service is pointing to https://myurl/web_services/doStuff,
I should be able to query https://myurl/web_services/doStuff?WSDL to get the WSDL
如果我的服务指向https://myurl/web_services/doStuff,
我应该能够查询https://myurl/web_services/doStuff?WSDL以获取WSDL
I am open to restarting the project if ServiceStack is no good, but it seems like hosting a WSDL should be kind of automatic.
如果ServiceStack不适用,我愿意重新启动项目,但似乎托管WSDL应该是自动的。
Here is my service code:
以下是我的服务代码:
public class MyServices : Service
{
public object Any(Envelope request)
{
return new EnvelopeResponse(request);
}
// should I have to have this method to get the WSDL?
public object Get(WSDL request)
{
return new WSDLResponse();
}
}
Here is my envelope class:
以下是我的信封类:
[Route("/web_services/doStuff", "POST")]
[DataContract]
public class Envelope : IReturn<EnvelopeResponse>
{
[DataMember(Name = "Header", Order = 0)]
public Header Header { get; set; }
[DataMember(Order = 1)]
public Body Body { get; set; }
}
When I try to manually return the WSDL it serializes the WSDL class into XML, so I would need to manually build a WSDL class, which doesn't feel right.
当我尝试手动返回WSDL时,它将WSDL类序列化为XML,因此我需要手动构建一个WSDL类,这感觉不对。
[Route("/web_services/doStuff", "GET")]
[DataContract]
public class WSDL : IReturn<WSDLResponse> {}
[DataContract]
public class WSDLResponse
{
public WSDLResponse()
{
// return wsdl file contents here?
Result = "wsdL";
}
[DataMember]
public string Result { get; set; }
}
Program.cs
以下是Program.cs:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
}
app.UseServiceStack(new AppHost());
app.Run();
I've looked over all the relevant ServiceStack documentation and I can not find anything helpful about WSDL
我已经查看了所有相关的ServiceStack文档,但未找到有关WSDL的有用信息。
I am either trying to create a new service from this WSDL, or host a WSDL from the same URL
我要么尝试从这个WSDL创建一个新的服务,要么从相同的URL托管一个WSDL。
英文:
I am trying to create a SOAP web service that will be consumed by another company. This company expects to give the data in a certain way, hence I have created a WSDL to reflect that.
I don't need to auto-generate the service from the WSDL, but if I could that would be nice.
I am just trying to create a service that will consume data, like the WSDL suggests. I am using .net core 6.
I have tried using serviceStack And I built out the envelope/header/body classes, such that it performs as desired. But it seems a little wonky because I am unable to query the WSDL.
If my service is pointing to https://myurl/web_services/doStuff,
I should be able to query https://myurl/web_services/doStuff?WSDL to get the WSDL
I am open to restarting the project if ServiceStack is no good, but it seems like hosting a WSDL should be kind of automatic.
Here is my service code:
public class MyServices : Service
{
public object Any(Envelope request)
{
return new EnvelopeResponse(request);
}
// should I have to have this method to get the WSDL?
public object Get(WSDL request)
{
return new WSDLResponse();
}
}
Here is my envelope class:
[Route("/web_services/doStuff", "POST")]
[DataContract]
public class Envelope : IReturn<EnvelopeResponse>
{
[DataMember(Name = "Header", Order = 0)]
public Header Header { get; set; }
[DataMember(Order = 1)]
public Body Body { get; set; }
}
When I try to manually return the WSDL it serializes the WSDL class into XML, so I would need to manually build a WSDL class, which doesn't feel right.
[Route("/web_services/doStuff", "GET")]
[DataContract]
public class WSDL : IReturn<WSDLResponse> {}
[DataContract]
public class WSDLResponse
{
public WSDLResponse()
{
// return wsdl file contents here?
Result = "wsdL";
}
[DataMember]
public string Result { get; set; }
}
Program.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
}
app.UseServiceStack(new AppHost());
app.Run();
I've looked over all the relevant ServiceStack documentation and I can not find anything helpful about WSDL
I am either trying to create a new service from this WSDL, or host a WSDL from the same URL
答案1
得分: 1
这几乎肯定不是你应该做的方式,但我成功地让 WSDL 在 GET 方法中显示。
我更新了我的服务以导入我手工制作的 WSDL,然后我添加了一个头部来返回 WSDL 作为 XML。
public class MyServices : Service
{
public object Any(Envelope request)
{
return new EnvelopeResponse(request);
}
[AddHeader(ContentType = MimeTypes.Xml)]
public object Get(WSDL request)
{
return System.IO.File.ReadAllText("myServiceName.wsdl");
}
}
英文:
This is almost certainly not how you are supposed to do it, but I managed to get the WSDL to display on get method.
I updated my service to import my handmade WSDL, then I added a header to return the WSDL as XML
public class MyServices : Service
{
public object Any(Envelope request)
{
return new EnvelopeResponse(request);
}
[AddHeader(ContentType = MimeTypes.Xml)]
public object Get(WSDL request)
{
return System.IO.File.ReadAllText("myServiceName.wsdl");
}
}
答案2
得分: 1
ServiceStack的SOAP支持在SOAP支持中有详细说明。
在/metadata页面,您可以解析所有服务的WSDL和XSD,例如:
其中包含到SOAP 1.1 / 1.2 WSDL端点的链接:
WSDLS
/soap12
/soap11
英文:
ServiceStack's SOAP Support is documented in SOAP Support.
Where you'll be able to resolve the WSDL and XSDs for all your Services from the /metadata page, e.g:
Which contains links to the SOAP 1.1 / 1.2 WSDL endpoints:
WSDLS
/soap12
/soap11
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论