|
Very nice article...
Cheers!
|
|
|
|
|
服务器端的Webservice.asmx如下:
///
/// 创建新用户
[SoapHeader("Credentials")]
[WebMethod(Description = "创建新用户")]
public DataSet CreateNewUser(String userName,
String password,
String nickName,
int sex,
String email,
String face,
String name,
String oicq,
String msn,
String leader)
{
// SecurityHelper.VerifyCredentials(this);
UserData retval = null;
if((new webteach.BusinessFacade.UserSystem()).
CreateUser(userName, password, nickName,
sex, email, face, name, oicq, msn, leader, out retval))
{
return retval;
}
else
{
//if(retval.Tables[0].Rows[0].RowError != String.Empty)
throw new SoapException(string.Empty,SoapException.ClientFaultCode,retval.Tables[0].Rows[0].RowError);
}
}
return (new webteach.BusinessFacade.UserSystem()).GetReplierListOnline(groupID, postID);
}
///
/// 根据用户名,用户密码得到用户基本信息
///
/// <param name="userName" />
/// <param name="password" />
/// <returns>
[SoapHeader("Credentials")]
[WebMethod(Description = "根据用户名,用户密码得到用户基本信息")]
public DataSet GetUserByUserName(String userName, String password)
{
SecurityHelper.VerifyCredentials(this);
return (new webteach.BusinessFacade.UserSystem()).GetUserByUserName(userName, password);
}
}
现在要用VC++6.0在客户端向服务器端Webservice.asmx注册一个新用户以及通过发送用户的username和password取得服务器发来的用户信息(一个DataSet),该如何办?
Zjroland from http://www.outsourcexp.com
|
|
|
|
|
Can communicate with a webservice running on Tomcat?
Tell me more about this.
Thanks in advance.
|
|
|
|
|
I have a webservice written in java and running on tomcat webserver using AXIS.
_bstr_t varWSDL = "http://localhost:8080/MyWSDL?wsdl";
_bstr_t varWSML = "";
_bstr_t bstrService = "MyServiceName";
_bstr_t bstrPort = "8080";
//Following line of code throws exception:
m_hr = m_pSoapClient->MSSoapInit2(varWSDL, varWSML, bstrService, bstrPort, bstrNS);
Thanks in advance!
-Umashankar H.M
|
|
|
|
|
Hey,
for some odd reason, in my program when the Invoke function from SoapClientBase is invoked, it returns saying "Type Mismatch" the arguments I am trying to pass are (int,int,int,string) ...they all seem to be initialized fine and the address of the VARIANT* pvarParams also comes through fine. The server side seems to be fine, the function there has 4 parameters as defined above.....Need some help here.
|
|
|
|
|
Hey uall....was able to fix my own problen.......dont send a the last variable string needed to be sent as a BSTR. If you need to fill a _variant_t array to send the parameters, you need to pass the address of the BSTR defined. In my code the thing goes like:
BSTR bStr;
bStr = SysAllocString(L"Hello World.");
int return_result = aluriaClient.GetScanResults(1,1,1, bStr);
In the receiving function when you call _variant_t to fill it up you need to do this ::
function(int A,int B,int C, BSTR something)
{
_variant_t varParams[4] = {A,B,C,&something};
_variant_t varResult;
.......
........
}
|
|
|
|
|
Thanks for this clean wrapper. You saved me so much time from doing all the busy work. Great job!
|
|
|
|
|
Hi, i have installed MS SOAP Toolkit3.0, the platform is WINDOWSXP+SP2, the code i wirte is listed below:
#include <stdio.h>
#import "msxml4.dll"
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib30;
void Get()
{
HRESULT hr;
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service.
hr = Connector.CreateInstance(__uuidof(HttpConnector30));
Connector->Property["EndPointURL"] = L"http://update.waytech.com.cn/Webservices/WTAU/WTAU.asmx?WSDL";
hr = Connector->Connect();
// Begin the message.
Connector->Property["SoapAction"] = L"http://www.waytech.com.cn/webservices/WTAU/WTAU0";
hr = Connector->BeginMessage();
// Create the SoapSerializer object.
hr = Serializer.CreateInstance(__uuidof(SoapSerializer30));
// Connect the serializer object to the input stream of the connector object.
hr = Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
// Build the SOAP Message.
hr = Serializer->StartEnvelope("", "", "");
// Serializer->SoapNamespace(L"xsi", L"http://www.w3.org/2001/XMLSchema-instance");
// Serializer->SoapNamespace(L"xsd",L"http://www.w3.org/2001/XMLSchema");
hr = Serializer->StartBody(L"");
Serializer->StartElement(L"request", "", "", "");
hr = Serializer->StartElement(L"WTAU1", "", "","");
// Serializer->SoapNamespace("", "http://www.waytech.com.cn/webservices/WTAU");
hr = Serializer->StartElement(L"Module", "", "", "");
hr = Serializer->StartElement(L"ProdType","","","");
hr = Serializer->WriteString(L"003");
hr = Serializer->EndElement();
hr = Serializer->StartElement(L"ProdSubType","","","");
hr = Serializer->WriteString(L"003.0001");
hr = Serializer->EndElement();
hr = Serializer->StartElement(L"Version","","","");
hr = Serializer->WriteString(L"1.0.0.0");
Serializer->EndElement();
hr = Serializer->StartElement(L"TimeStamp","","","");
hr = Serializer->WriteString(L"2004 12 31 00:00:00");
hr = Serializer->EndElement();
hr = Serializer->StartElement(L"Name","","","");
hr = Serializer->WriteString(L"RV.EXE");
hr = Serializer->EndElement();
hr = Serializer->StartElement(L"FileName","","","");
hr = Serializer->WriteString(L"RV.EXE");
hr = Serializer->EndElement();
hr = Serializer->EndElement();
hr = Serializer->EndElement();
Serializer->EndElement();
hr = Serializer->EndBody();
hr = Serializer->EndEnvelope();
// Send the message to the XML Web service.
hr = Connector->EndMessage();
// Read the response.
hr = Reader.CreateInstance(__uuidof(SoapReader30));
// Connect the reader to the output stream of the connector object.
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
// Display the result.
printf("Answer: %s\n", (const char*)Reader->Dom->xml);
}
int main()
{
CoInitialize(NULL);
Get();
CoUninitialize();
return 0;
}
I use a protocol sniffer to capture the request message it generate and found it is like these:
<?xml **UnReg**1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="">
<request SOAP-ENV:encodingStyle="">
<WTAU1 SOAP-ENV:encodingStyle="">
<Module SOAP-ENV:encodingStyle="">
<ProdType SOAP-ENV:encodingStyle="">003</ProdType>
<ProdSubType SOAP-ENV:e**UnReg**yle="">003.0001</ProdSubType>
<Version SOAP-ENV:encodingStyle="">1.0.0.0</Version>
<TimeStamp SOAP-ENV:encodingStyle="">2004 12 31 00:00:00</TimeStamp>
<Name SOAP-ENV:encodingStyle="">RV.EXE</Name>
<FileName SOAP-ENV:encodingStyle="">RV.EXE</FileName>
</Module>
</WTAU1>
</request>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
you can see that the first line is wrong, the node "ProdSubType" is wrong too, why will this happen, what should i do to sovle this problem, i hope you can help me.
learn to be still.
|
|
|
|
|
What sniffer did you use and how did you set it up?
Was its proxyTrace or tcpTrace. Let me know how you set up the desitnation, etc..
It seems to me that one of your parameters are wrong.
Jack Steel
|
|
|
|
|
Anyone know the solutions and some demo code ?
|
|
|
|
|
hi there!
hope it's not late. you have to use base64string for sending binary data via xml.
HTH
Scarlaxx
|
|
|
|
|
Hi. Im using your class to connect to a Microsoft Project Server.
I've managed to initialize it and now im autenticating myself, and that's where the problem is!
I think im passing the right parameters, cause i dont get E_INVALIDARG and im perfectly sure im using the right method call. The return value i get is:
m_hr 0x80020005 Type mismatch. HRESULT
and the return variant is of type VT_EMPTY. After some search, it seems that this error occurs when the return type is not of the same type of the return variable u pass it. I've tried to do this:
varResult.ChangeType(VT_BSTR,&varResult);
...as it was supposed to return a string, but i still get the same error.
Any ideas??? I dont just know if its a return type problem or a feed-parameter problem!
Thanks in advance!
|
|
|
|
|
Hey I am having the wxact samr problem......did you find a solution to it ?
|
|
|
|
|
Hi,
Is your problem exactly with MS Project Server?
Anyway, i gave up on that approach and got it working on .NET
If you're not keen (or cant) on moving your app to C#, VB.NET, you could do 1 of the follow:
1 - Wait for VS 2005 (1 month or so). The VC++ managed code seems to be good to use now.
2 - Make a .NET dll with this function encapsulated
3 - Dig a bit more on the subject. I wouldnt do that, cause sooner or later you'll end up in a dead end.
|
|
|
|
|
Hey uall....was able to fix my own problen.......dont send a the last variable string needed to be sent as a BSTR. If you need to fill a _variant_t array to send the parameters, you need to pass the address of the BSTR defined. In my code the thing goes like:
BSTR bStr;
bStr = SysAllocString(L"Hello World.");
int return_result = aluriaClient.GetScanResults(1,1,1, bStr);
In the receiving function when you call _variant_t to fill it up you need to do this ::
function(int A,int B,int C, BSTR something)
{
_variant_t varParams[4] = {A,B,C,&something};
_variant_t varResult;
.......
........
}
|
|
|
|
|
string response(string arg1,string arg2)
I don't know how to extract the string from the following code:
/******************************************
void IsAuthorized(LPCTSTR username, LPCTSTR password , char* str)
{
_variant_t varParams[2] = { password, username };
_variant_t varResult;
m_hr = Invoke(L"IsAuthorized", varParams, 2, &varResult);
// here is my problem !!!
return VARIANT_TRUE == varResult.boolVal;
}*******************************************************/
I don't know how to manipulate _variant_t and I didn't find information to do what i want.
thank you for your help
|
|
|
|
|
BSTR response(LPCTSTR arg1, LPCTSTR arg2)
{
_variant_t varParams[2] = { arg2, arg1};
_variant_t varResult;
m_hr = Invoke(L"response", varParams, 2, &varResult);
return varResult.Detach().bstrValue;
}
Does that answer you question?
|
|
|
|
|
just half.
I need to convert BSTR type to char* type.
Is it possible ??
|
|
|
|
|
and to convert char* to BSTR of course.
I was not able to use the help in the MSNDN
|
|
|
|
|
ATL Micro OLE2T and T2BSTR is the most convenient way to convert strings between BSTR and char*
You should prepare your MSDN to continue developing. You will certainly have more questions. Most of them should be answered by MSDN, instead of somebody else.
|
|
|
|
|
|
I'm totally new to this. I'm trying to change your sample to access the Google web services API. Currently, I cannot get past the Init() call. My *very* simple code looks like:
AuthServiceClient service;
::CoInitialize( NULL );
service.Init("http://api.google.com/GoogleSearch?wsdl","doGoogleSearch","GoogleSearchPort");
// bool bResult = service.IsAuthorized( "Name", "Password" );
::CoUninitialize();
return 0;
I'm getting an exception in the Init call. Any ideas what I am doing wrong?
Thanks.
|
|
|
|
|
Solved my own problem. Should have waited to post. Had the wrong servicename. Should be:
service.Init
(
"http://api.google.com/GoogleSearch.wsdl",
"GoogleSearchService",
"GoogleSearchPort"
);
|
|
|
|
|
I'm creating an C# web service for to VC6 client (exactly is VC7 unmanage code).
I have done exactly as you say. It complie but I can't manage to Invoke the web service. It always make error message that "Create soap client object fail". My WS is work fine when call from C# client. The SOAP toolkit include
path is right. Is there any thing else I have done to make the program run?
bool CWSClient::Call()
{
Init("http://mt-it3/eFaxService/service1.asmx?wsdl", "eFaxService", "");
try
{
_variant_t varParams[2] = {"user1", "abcd12"};
_variant_t varResult;
HRESULT m_hr = Invoke(L"CheckLogin", varParams, 2, &varResult);
}
catch (...)
{
}
return 1;
}
|
|
|
|
|
I'm now accessed the WS. But there are another error that I don't know how to solve I can only access simple Web method. For example if I call the very simple method follow it work fine:
[WebMethod]
public int CheckLogin(string strUserID, string strPassword)
{
int nPrior = 10;
if(nPrior >= 0)
{
Application["UserID"] = strUserID.ToLower();
}
return nPrior;
}
But when I implement real method that call a mangage database class to check
user priority, that always fail
[WebMethod]
public int CheckLogin(string strUserID, string strPassword)
{
CDBUser dbUser = new CDBUser();
int nPrior = dbUser.Login(strUserID, strPassword);
if(nPrior >= 0)
{
Application["UserID"] = strUserID.ToLower();
}
return nPrior;
}
I don't understand why it that because the Web method interface is no change and if I call the WS from a C# client by .Net Add reference method it work fine. Can you show me where is the problem? In my WS method, or in calling WS from SOAP toolkit 3. The calling code is the same as the previous message.
Thanks in advance.
|
|
|
|
|