gSoap C++ - C# deserialization issue - c#

I have defined a function called login that should return a token. The token has a security id which is a char*
SOAP_FMAC5 int SOAP_FMAC6 __afas__login(struct soap* env, afas__Login *afas__login, afas__LoginResponse *afas__loginResponse)
{
int ret = ServiceApp::GetServiceApp()->GetServiceImpl()->login(afas__login->user, afas__login->password);
afas__loginResponse->error = soap_new_afas__Error(env, -1);
afas__loginResponse->af__token = soap_new_af__Token(env, -1);
if (ret == sERROR)
{
afas__loginResponse->error->code = afas__ErrorCode__NOTLOGGEDIN;
}
else
{
afas__loginResponse->error->code = afas__ErrorCode__SUCCESS;
afas__loginResponse->af__token->sessionId = soap_strdup(env, soap_int2s(env, ret));
afas__loginResponse->af__token->securityId = soap_strdup(env, afas__login->password);
afas__loginResponse->af__token->userName = soap_strdup(env, afas__login->user);
}
return SOAP_OK;
}
On the client side I have a call to this :
AuthenticationServiceClient a = new AuthenticationServiceClient();
Login login = new Login();
login.user = "test";
login.password = "test";
LoginResponse lr = a.login(login);
string securityId = lr.token.sessionId
The problem is that secuirtyId is null. Somehow it doesn't get deserialized.
On the other hand, the error Code, which is an integer is deserialized correctly.
Any suggestions ?

The problem comes from the wsdl file. Looking at gSOAP docs I found:
http://www.cs.fsu.edu/~engelen/soapfaq.html
<x:foo xmlns:x="urn:foo" xmlns="urn:bar">
<bar></bar>
</x:foo>
In the last example the bar element belongs to the "urn:bar" namespace, because the default namespace is "urn:bar". With Visual Studio .NET 2003 WSDL import, we could not successfully deserialize data from a multi-namespace situation when a response element contains an element of struct type in a second namespace. The individual members of the struct were ignored on the .NET side until the element form default 'qualified' was defined.
So setting attributeFormDefault="qualified" and elementFormDefault="qualified" fixed the serialization issue.

Related

WSDL generated service reference returning null

Im have some issues with a service reference to an external source (added it using the supplied wsdl in Visual Studio 2015).
The situation is that the request i run seems to reach the server fine. I also seems to get a response of the expected xml format (added TextWriterTraceListener). But the OutType class i get back in the code (in this case the GetBankCertificateOutType) is always null.
The console application ive built to illustrate is very simple, utilizing the public test account. It looks as follows:
static void Main(string[] args)
{
//instantiates client from the service reference
var client = new PkiServicePortTypeClient();
var time = DateTime.UtcNow;
Random r = new Random();
string reqId = r.Next(100, 999).ToString();
var outType = client.GetBankCertificate(*full params on github*);
//This line will throw nullexception since outType is always null
//BUT a valid response is actually received (although returning aa application statusCode that represents error at this stage)
var response = outType.GetBankCertificateResponse;
}
Ive tried to locate the problem but have been unsuccessful sofar. So wanted to see if someone has some good tip on how to debug this or perhaps has a solution.
I built a complete, minimal, console sample project (including the source wsdl) to illustrtate the issue which is located here.
I've downloaded and inspected your solution, and I found this in trace.log
GetBankCertificateRequest at tribute {http://www.w3.org/XML/1998/namespace}id had invalid value '360817' of type '{http://www .w3.org/2001/XML Schema}ID'
After I played with id value of GetBankCertificateRequest I got back the right value (instead of null).
var outType = client.GetBankCertificate(new GetBankCertificateInType {
RequestHeader = new RequestHeaderType {
SenderId = "360817",
CustomerId = "360817",
RequestId = reqId,
Environment = EnvironmentType.test,
EnvironmentSpecified = true,
InterfaceVersion = "1",
Timestamp = time
},
GetBankCertificateRequest = new GetBankCertificateRequest {
BankRootCertificateSerialNo = "1111110002",
//id = "",
RequestId = reqId,
Timestamp = time
}
});
There is no description for this property according to documentation (PKI service description v2.3.pdf) except some xml type annotation (xml:id). The concrete schema description is missing.

Create Timesheet using PSI Project Server 2013 - General Invalid Operation

I'm trying to use the TimeSheet.CreateTimesheet method from msdn but unfortunately I receive the General Invalid Operation error from my console.
I suspect it's a permissions problem, because of I have followed all of the instructions posted in the entrance from msdn linked before.
Here are the MAIN code:
// Here are the variables
SvcTimeSheet.TimesheetDataSet timesheetDs;
SvcTimeSheet.TimeSheet timeSheetSvc = new SvcTimeSheet.TimeSheet();
timeSheetSvc.UseDefaultCredentials = true;
timeSheetSvc.Url = PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH;
Guid myUid = resourceSvc.GetCurrentUserUid();
SvcAdmin.TimePeriodDataSet timeperiodDs = adminSvc.ReadPeriods(SvcAdmin.PeriodState.Open);
Guid periodUid = timeperiodDs.TimePeriods[0].WPRD_UID;
// Here are the Timesheet creation method
timesheetDs = new SvcTimeSheet.TimesheetDataSet();
SvcTimeSheet.TimesheetDataSet.HeadersRow headersRow = timesheetDs.Headers.NewHeadersRow();
headersRow.RES_UID = myUid;
headersRow.TS_UID = Guid.NewGuid();
headersRow.WPRD_UID = periodUid;
headersRow.TS_CREATOR_RES_UID = myUid;
headersRow.TS_NAME = "Timesheet ";
headersRow.TS_COMMENTS = "Random comment text here";
headersRow.TS_ENTRY_MODE_ENUM = (byte)PSLibrary.TimesheetEnum.EntryMode.Weekly;
timesheetDs.Headers.AddHeadersRow(headersRow);
// Create the timesheet with the default line types that are specified by the admin.
timeSheetSvc.CreateTimesheet(timesheetDs, SvcTimeSheet.PreloadType.Assignments);
timesheetDs = timeSheetSvc.ReadTimesheet(headersRow.TS_UID);
When timeSheetSvc.CreateTimesheet(timesheetDs, SvcTimeSheet.PreloadType.Assignments); it is called, I get the General Invalid Operation.
Anybody knows what that means? Or where can I find further information about?
EDIT:
Here are the screenshot from my PSI Console, that parses the error:
Thanks in advance,

I can't add web reference from wsdl

I can't add the web reference from a wsdl file. I am getting an error.
But it is working normally with SoapUI.
"RPC Message getFaturaResponse in operation getKurumSTFatura has an invalid body name getFaturaResponse. It must be getKurumSTFaturaResponse"
abonePortTypeClient client = new abonePortTypeClient();
if (client.State != CommunicationState.Faulted)
{
string outresult = string.Empty;
var param35 = new AboneClient.SahaIsemri();
param35.tesisatno = 1;
param35.emirturu = 7;
param35.altemirturu = 5;
param35.elemankodu = 3208;
string resultstring = null;
var SahaIsemri = new AboneClient.SahaIsemri();
client.ClientCredentials.UserName.UserName = "XXX";
client.ClientCredentials.UserName.Password = "XXX";
var aaa = client.putSahaIsemri(param35, out resultstring, out SahaIsemri);
}
It refers that the references generated by wsdl does not match.
getFaturaResponse in operation getKurumSTFatura has an invalid body name getFaturaResponse. It must be getKurumSTFaturaResponse
You need to change the Operation in the service or you need to manually change in the reference.cs file.
Search for the particular method and rename the response as above!
#Sajeetharan's answer is fine, but I had some problems finding what I had to rename. Just in case it can help someone, you have to look for the WrapperName in the MessageContractAttribute. In the example above, it would be something like:
[System.ServiceModel.MessageContractAttribute(WrapperName="getKurumSTFatura", WrapperNamespace="xxxx", IsWrapped=true)]
public partial class getFaturaResponse {

Upload file to Sharepoint 2013 using web service - Object reference not set to an instance of an object

I'm trying to upload file to Sharepoint 2013 using web service copy.asmx
I've created simple project with the following method:
public bool UploadFile(string file, string destination)
{
bool success = false;
CopySoapClient client = new CopySoapClient();
if (client.ClientCredentials != null)
{
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("admin", "password", "domain");
}
try
{
client.Open();
string filename = Path.GetFileName(file);
string destinationUrl = destination +#"/"+ filename;
string[] destinationUrls = { destination };
FieldInformation i1 = new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = filename};
FieldInformation[] info = { i1 };
CopyResult[] result;
byte[] data = File.ReadAllBytes(file);
uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);
if (result != null && result.Length > 0 && result[0].ErrorCode == 0)
success = true;
}
finally
{
if (client.State == System.ServiceModel.CommunicationState.Faulted)
client.Abort();
if (client.State != System.ServiceModel.CommunicationState.Closed)
client.Close();
}
return success;
}
CopySoapClient is part Copy service reference
http://SPSITE/_vti_bin/copy.asmx
The method is called using following parameters:
UploadFile(#"C:\temp\test.txt", "http://SPSITE/sites/Connector/documents/test.txt");
The problem is, when program executes
uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);
the web service returns in result "Unknown error" with description "Object reference not set to an instance of an object."
I really don't know what I'm missing. Can anyone help me out?
Thank you.
P.S. I've noticed in examples provided on the Internet that people are using a Copy class from copy.asmx. But I only have CopySoapClient class.
you used the right web services but on wrong SharePoint site. Try to make this web services reference on the same sharepoint site you have posted here as target library.
missing the OPTIONAL element of <Fields> and <FieldInformation >, resulted ErrorCode="Unknown" ErrorMessage="Object reference not set to an instance of an object." . even though, Field and FieldInformation supposed to be optional. It could be the server side configuration. Anyway, it works for me now, adding all attributed, required/optional.

Getting the Manufacturer's Name for a Given Product ID using Magento SOAP API V2 in C#

I am in need of getting the manufacturer's name, given a product code. The following code stub returns the manufacturer's ID (values like 109, 120, etc.). Is there a way to get the manufacturer's name insted of the ID? I can see that there are some good examples in PHP for this question but I am looking for the answer in C#. Any help would be greatly appreciated! Thanks in anticipation!
The current code is:
public bool GetProductInfo(salesOrderItemEntity objProduct, ref StructProductInfo structProductInfo)
{
bool bSuccess = false;
catalogProductRequestAttributes attrib = new catalogProductRequestAttributes();
attrib.additional_attributes = new string[] { "manufacturer" };
catalogProductReturnEntity objProductInfo = null;
objProductInfo = mservice.catalogProductInfo(mlogin, objProduct.product_id, "default", attrib, null);
if (null != objProductInfo)
{
associativeEntity[] assoc = objProductInfo.additional_attributes;
structProductInfo.ManufacturerCode = assoc[0].value;
bSuccess = true;
}
return bSuccess;
}
Manufacturer is an integer "eav_attribute" by default, and that is why you will get integer values.
You will need to get the join to the manufacturers data set up in magneto.
Not exactly sure how to do that data from the API end.
Maybe try attribute options, instead of additional attributes, and then get the label for that option.
Figured out how to do this. "102" is the attribute code for "manufacturer". Using this with catalogProductAttributeOptions(), I have built a small hashtable-based lookup for getting a manufacturer's name, given the manufacturer's code.
public void CreateManufacturerLookup()
{
mhtManufacturers.Clear(); // mhtManufacturers is a hashtable declared with class scope
catalogAttributeOptionEntity[] caoe = mservice.catalogProductAttributeOptions(mlogin, "102", "default"); // mlogin is the session ID and is available at class scope
if (caoe.Length > 0)
{
for (int i = 0; i < caoe.Length; i++)
{
mhtManufacturers.Add(caoe[i].value, caoe[i].label);
}
}
}
So, manufacturer's name can be obtained by looking up as follows:
sManufacturerName = (string) mhtManufacturers[sManufacturerCode];

Categories