如果有人不调用 Web 服务,将数据发布到 URL 的最佳方式是什么?
好吧...我有一个大问题...好吧这里...通常如果我理解得很好...Web 服务的工作方式是我编写一个方法从数据库获取一些数据,然后再获取一些数据其他用户/客户端添加引用并调用我的服务并获取数据...现在就我而言,我必须获取数据并实际将其以 xml 形式发布到用户/客户端(也许是肥皂)我猜...所以这就是我所做的......
[Serializable]
public class MyClass
{ [SoapAttribute]
public int id;
[SoapIgnore]
public int ToSkip;
}
String XmlizedString = null;
MyClass obj= new MyClass ();
MemoryStream memoryStream = new MemoryStream ( );
XmlTypeMapping myMapping =
(new SoapReflectionImporter().ImportTypeMapping
(typeof(MyClass)));
XmlSerializer xs = new XmlSerializer (myMapping);
XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 );
xs.Serialize ( xmlTextWriter, obj );
memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString ( memoryStream.ToArray ( ) );
using (System.Net.WebClient client = new System.Net.WebClient())
{
// performs an HTTP POST
status= client.UploadString("http:/somewebservice.com/" + webServiceName, XmlizedString);
}
所以基本上......我将其序列化为xml(和soap)并将其转换为字符串,然后将此字符串上传到Web服务url...... 我只是想知道我所做的是否正确?...我基本上想将数据转换为soap xml,然后将其发送到用户的网络服务网址...请帮助我...
Alright...I have kind of a big quesstion...ok here goes...Usually if i understand it well...web services work in a way that i write a method to get some data from the database and then some other user/client adds a reference and calls my service and gets the data...now in my case i have to get the data and actually post it to the user/client in xml(in soap maybe) i guess....so here is what i do...
[Serializable]
public class MyClass
{ [SoapAttribute]
public int id;
[SoapIgnore]
public int ToSkip;
}
String XmlizedString = null;
MyClass obj= new MyClass ();
MemoryStream memoryStream = new MemoryStream ( );
XmlTypeMapping myMapping =
(new SoapReflectionImporter().ImportTypeMapping
(typeof(MyClass)));
XmlSerializer xs = new XmlSerializer (myMapping);
XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 );
xs.Serialize ( xmlTextWriter, obj );
memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString ( memoryStream.ToArray ( ) );
using (System.Net.WebClient client = new System.Net.WebClient())
{
// performs an HTTP POST
status= client.UploadString("http:/somewebservice.com/" + webServiceName, XmlizedString);
}
So basically....I serialize it to xml(and soap) and convert it to string and then upload this string to the web service url......
I just want to know if what i am doing is right?...i want to basically get the data convert it to soap xml and then send it over to the user's web service url....please help me out...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是基于 wsdl 的 Web 服务吗?如果是,那么只需使用 IDE 或某些工具来生成静态类型的客户端包装器。
在.NET环境中,可以使用Visual Studio或
wsdl.exe
不要将原始数据发送到 url,也不要尝试手动解析响应,这太疯狂了。尤其是对于这些复杂的基于 SOAP 的 Web 服务。
Is this wsdl-based webservice? If yes, then just use your IDE or some tool to generate static-typed client wrapper.
In .NET environment, you can use visual studio or
wsdl.exe
Don't send raw data to url and don't try to parse response manually, that's insane. Especially with these complex SOAP-based webservices.