I have a program that is consuming an external web service. 1 of the fields I need to send in the request is a DateTime field however it seems to never be present even though I have set it, along with many others in the same object, and they are passed fine.
I put a message inspector and had a look at what it is sending, here is the request:
<bettingRequest xmlns="">
<accountPin>0</accountPin>
<betDetailsRequestList>
<acceptPartial>0</acceptPartial>
<accumulatorBet>false</accumulatorBet>
<accumulatorId>0</accumulatorId>
<allUpFormula>0</allUpFormula>
<betAmountList>
<amountInvested>25</amountInvested>
<returnsPerBet>0</returnsPerBet>
</betAmountList>
<betRefId>0</betRefId>
<betType>Parimutuel</betType>
<scheduledType>1</scheduledType>
<fixedOddsProdCode>0</fixedOddsProdCode>
<flexiBet>false</flexiBet>
<legList>
<prodCode>1</prodCode>
<propositionNumber>0</propositionNumber>
<raceNumber>2</raceNumber>
<selectionList>
<selectionName>TIM FIN</selectionName>
<selectionNumber>6</selectionNumber>
<selectionSeparator />
</selectionList>
</legList>
<mystery>false</mystery>
<notifyMethod>0</notifyMethod>
<numMultiParlayBet>0</numMultiParlayBet>
<ordinalNumber>1</ordinalNumber>
<meetingCode>13</meetingCode>
</betDetailsRequestList>
</bettingRequest>
and here is what creates it:
bettingRequest betReq = new bettingRequest();
betDetailsReq betDetReq = new betDetailsReq();
List<legDetailsReq> leglist = new List<legDetailsReq>();
List<betSelection> sellist = new List<betSelection>();
List<betAmount> betamtlist = new List<betAmount>();
List<betDetailsReq> betdetaillist = new List<betDetailsReq>();
betSelection sel = new betSelection();
sel.selectionNumber = selection.ToString();
sel.selectionName = Runner;
sel.selectionSeparator = "";
sellist.Add(sel);
legDetailsReq leg = new legDetailsReq();
leg.prodCode = 1;
leg.propositionNumber = 0;
leg.raceNumber = racenum;
leg.selectionList = sellist.ToArray();
leglist.Add(leg);
betAmount betAmt = new betAmount();
betAmt.amountInvested = betamt;
betAmt.returnsPerBet = "0";
betamtlist.Add(betAmt);
betDetReq.betType = "Parimutuel";
betDetReq.betAmountList = betamtlist.ToArray();
betDetReq.legList = leglist.ToArray();
betDetReq.allUpFormula = "0";
betDetReq.acceptPartial = 0;
betDetReq.accumulatorBet = false;
betDetReq.betRefId = 0;
betDetReq.scheduledType = 1;
betDetReq.fixedOddsProdCode = 0;
betDetReq.flexiBet = false;
betDetReq.mystery = false;
betDetReq.notifyMethod = 0;
betDetReq.ordinalNumber = 1;
betDetReq.meetingCode = meetingcode;
betDetReq.meetingDate = DateTime.Now;
betdetaillist.Add(betDetReq);
betReq.betDetailsRequestList = betdetaillist.ToArray();
bettingResponse resp = bet.validateBet(meta, betReq);
and here is the code for the serialization:
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=11)]
public System.DateTime meetingDate {
get {
return this.meetingDateField;
}
set {
this.meetingDateField = value;
this.RaisePropertyChanged("meetingDate");
}
}
The attribute that is missing is the betDetReq.meetingDate, the WSDL can be viewed at https://api.tab.com.au/tabapi/services/betting?wsdl
Can someone tell me where I am going wrong please? I have tried many different variations of DataTime all with the same missing result.
Thanks
Dean
Ensure you have set the "Specified" property to true.
betDetReq.meetingDate = DateTime.Now;
betDetReq.meetingDateSpecified = true;
If you have an optional field (i.e. one where the minOccurs attribute is 0), then the proxy includes a "Specified" property. Unless you set this to true, the field does not get added to the request body.
Related
I have an Amazon EC2 instance and I need to be able to create an AMI (image) from it programmatically. I'm trying the following:
CreateImageRequest rq = new CreateImageRequest();
rq.InstanceId = myInstanceID;
rq.Name = instance.KeyName;
rq.Description = "stam";
rq.NoReboot = true;
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
try
{
imageResp = ec2.CreateImage(rq);
}
catch (AmazonServiceException ase)
{
MessageBox.Show(ase.Message);
}
The result is always an AmazonServiceException saying that there is a NameResolutionFailure.
How do I overcome this? I tried different possible "name" possibilities but cannot find the right one.
string amiID = ConfigurationManager.AppSettings[AmazonConstants.AwsImageId];
string keyPairName = ConfigurationManager.AppSettings[AmazonConstants.AwsKeyPair];
List<string> groups = new List<string>() { ConfigurationManager.AppSettings[AmazonConstants.AwsSecurityGroupId] };
var launchRequest = new RunInstancesRequest()
{
ImageId = amiID,
InstanceType = ConfigurationManager.AppSettings[AmazonConstants.AwsInstanceType],
MinCount = 1,
MaxCount = 1,
KeyName = keyPairName,
SecurityGroupIds = groups,
SubnetId = ConfigurationManager.AppSettings[AmazonConstants.AwsSubnetId]
};
RunInstancesResponse runInstancesResponse = amazonEc2client.RunInstances(launchRequest);
RunInstancesResult runInstancesResult = runInstancesResponse.RunInstancesResult;
Reservation reservation = runInstancesResult.Reservation;
Problem eventually solved!
it turned out thyat some codelines were doing things which were already done already and removing this part:
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
Made things clearer and no wrong repetitions happened! Now it works!
From my WCF Service, I need to create a purchase order in SAP system and it's creating. But when I tried to commit the transaction it's not effecting in SAP system.
I am getting PONumber from SAP and it's not committing.
Can any one help me on this issue.
Here is my code:
NFCLMasters.ZMASTERDATA zmobj = new NFCLMasters.ZMASTERDATA();
NFCLMasters.ZMASTERDATAResponse zmresponse = new NFCLMasters.ZMASTERDATAResponse();
NFCLMasters.ZSM_WH_MST[] zmwarehousemaster = new NFCLMasters.ZSM_WH_MST[10];
NFCLMasters.zws_mst mst = new NFCLMasters.zws_mst();
zmobj.IWHMST = "X";
zmobj.WHMST_LINES = zmwarehousemaster;
zmresponse = mst.ZMASTERDATA(zmobj);
NFCLTransactions.BAPI_PO_CREATE1 Zpo = new NFCLTransactions.BAPI_PO_CREATE1();
NFCLTransactions.BAPI_PO_CREATE1Response Zporesponse = new NFCLTransactions.BAPI_PO_CREATE1Response();
NFCLTransactions.zws_lo SapTrasactions = new NFCLTransactions.zws_lo ();
// Data objects
NFCLTransactions.BAPIMEPOHEADER poheader = new NFCLTransactions.BAPIMEPOHEADER();
NFCLTransactions.BAPIMEPOHEADERX poheaderx = new NFCLTransactions.BAPIMEPOHEADERX();
NFCLTransactions.BAPIMEPOITEM[] poitem = new NFCLTransactions.BAPIMEPOITEM[1];
NFCLTransactions.BAPIMEPOITEMX[] poitemx = new NFCLTransactions.BAPIMEPOITEMX[1];
NFCLTransactions.BAPIMEPOSCHEDULE[] poschedule = new NFCLTransactions.BAPIMEPOSCHEDULE[1];
NFCLTransactions.BAPIMEPOSCHEDULX[] poschedulex = new NFCLTransactions.BAPIMEPOSCHEDULX[1];
NFCLTransactions.BAPIITEMSHIP[] poitemship = new NFCLTransactions.BAPIITEMSHIP[1];
NFCLTransactions.BAPIITEMSHIPX[] poitemshipx = new NFCLTransactions.BAPIITEMSHIPX[1];
NFCLTransactions.BAPIRET2[] Bapireturn = new NFCLTransactions.BAPIRET2[100];
// ASSIGNING VALUES TO EACH OBJECT AND ADDING MAIN BAPI
poheader.COMP_CODE = "NFCL"; poheader.DOC_TYPE = "ZPPS"; poheader.PURCH_ORG = "MKTG"; poheader.PUR_GROUP = "M13"; poheader.DOC_DATE = "2015-02-06";
poheader.SUPPL_PLNT = "1311"; poheader.OUR_REF = "R006";
Zpo.POHEADER = poheader;
poheaderx.COMP_CODE = "X"; poheaderx.DOC_TYPE = "X"; poheaderx.PMNTTRMS = "X"; poheaderx.PURCH_ORG = "X"; poheaderx.PUR_GROUP = "X";
poheaderx.SUPPL_PLNT = "X"; poheaderx.OUR_REF = "X";
Zpo.POHEADERX = poheaderx;
poitem[0] = new NFCLTransactions.BAPIMEPOITEM();
poitem[0].PO_ITEM = "00001"; poitem[0].MATERIAL = "U01016501F"; poitem[0].PLANT = "1311"; poitem[0].STGE_LOC = "K038"; poitem[0].QUANTITY = 10;
poitem[0].PERIOD_IND_EXPIRATION_DATE = "D";
Zpo.POITEM = poitem;
poitemx[0] = new NFCLTransactions.BAPIMEPOITEMX();
poitemx[0].PO_ITEM = "00001"; poitemx[0].MATERIAL = "X"; poitemx[0].PLANT = "X"; poitemx[0].STGE_LOC = "X"; poitemx[0].QUANTITY = "X";
poitemx[0].VAL_TYPE = "X"; poitemx[0].BATCH = "X";
Zpo.POITEMX = poitemx;
poschedule[0] = new NFCLTransactions.BAPIMEPOSCHEDULE();
poschedule[0].PO_ITEM = "00001"; poschedule[0].DELIVERY_DATE = "06.02.2015"; poschedule[0].QUANTITY = 10;
//poschedule[0].DELIV_TIME = 'X';
// poschedule[0].GR_END_TIME
Zpo.POSCHEDULE = poschedule;
poschedulex[0] = new NFCLTransactions.BAPIMEPOSCHEDULX();
poschedulex[0].PO_ITEM = "00001"; poschedulex[0].PO_ITEMX = "X"; poschedulex[0].DELIVERY_DATE = "X"; poschedulex[0].QUANTITY = "X";
Zpo.POSCHEDULEX = poschedulex;
poitemship[0] = new NFCLTransactions.BAPIITEMSHIP();
poitemship[0].PO_ITEM = "00001"; poitemship[0].SHIP_POINT = "R006";
Zpo.POSHIPPING = poitemship;
poitemshipx[0] = new NFCLTransactions.BAPIITEMSHIPX();
poitemshipx[0].PO_ITEM = "00001"; poitemshipx[0].SHIP_POINT = "X";
Zpo.POSHIPPINGX = poitemshipx;
Zpo.RETURN = Bapireturn;
NFCLTransactions.BAPI_TRANSACTION_COMMIT transcommit = new NFCLTransactions.BAPI_TRANSACTION_COMMIT();
transcommit.WAIT = "X";
Zporesponse = SapTrasactions.BAPI_PO_CREATE1(Zpo);
response = Zporesponse.EXPPURCHASEORDER;
NFCLTransactions.BAPI_TRANSACTION_COMMITResponse resp = SapTrasactions.BAPI_TRANSACTION_COMMIT(transcommit);
Your two BAPI calls are currently executed in individual contexts. Therefore the second call to BAPI_TRANSACTION_COMMIT won't work because the second call context doesn't know anything about the results from the first call. You need to execute both calls within the same context. I don't know how to do that with the old, deprecated SAP .Net Connector, but with the current SAP Nco 3 you can achive it by using the methods RfcSessionManager.BeginContext() and RfcSessionManager.EndContext().
If the BAPIs are only exposed as web services, a commit probably won't succeed because all calls to those web services are executed in their own context, so you have the same problem again. A workaround for using web services and BAPI_TRANSACTION_COMMIT would be to create a custom function module in the SAP system that first calls your BAPI and if that call succeeds, calls BAPI_TRANSACTION_COMMIT. That function module would have to be RFC capable and could be exposed as a web service for you. The parameters for that custom function module would (at least) be the same as for the BAPI you need, maybe an additional "COMMIT" parameter to allow you calling it without committing anything. Creating such a function module is relatively easy and shouldn't be a problem for a company familiar with SAP ERP.
I am working on Expedia hotel API.All the function are working except booking.All the other request using GET method for requesting.But in booking we have to use the POST method with different URL.So i changed the URL for request but still getting the error.
My codes are
HotelServicesImplService client = new HotelServicesImplService();
HotelRoomReservationRequest bookreq = new HotelRoomReservationRequest();
HotelRoomReservationResponse bookres = new HotelRoomReservationResponse();
addressInfo bookad = new addressInfo();
reservationInfo bookinfo = new reservationInfo();
client.Url = "https://book.api.ean.com/ean-services/rs/hotel/v3";
//bookreq.minorRevSpecified = true;
//bookreq.minorRev = 25;
bookreq.hotelId = 106347;
bookreq.apiKey = "api";
bookreq.cid = "cid";
bookreq.arrivalDate = "12/11/2013";
bookreq.departureDate = "12/13/2013";
bookreq.supplierType = SupplierType.E;
bookreq.rateKey = "af00b688-acf4-409e-8bdc-fcfc3d1cb80c";
bookreq.roomTypeCode = "198058";
bookreq.rateCode = "484072";
bookreq.RoomGroup = new[] { new Room
{
numberOfAdults=Convert.ToInt32(2),
numberOfChildren=Convert.ToInt32(0),
childAges=new int[] {} ,
firstName="Test Booking",
lastName="Test Booking",
bedTypeId="23",
smokingPreference=SmokingPreference.NS,
}};
float i = float.Parse("231.18");
bookreq.currencyCode = "USD";
bookreq.chargeableRate = i;
bookinfo.email = "ranaabhi007#yahoo.com";
bookinfo.firstName = "TestBooking";
bookinfo.lastName = "TestBooking";
bookinfo.homePhone = "2145370159";
bookinfo.workPhone = "2145370159";
bookinfo.creditCardType = "CA";
bookinfo.creditCardNumber = "5401999999999999";
bookinfo.creditCardIdentifier = "TestBooking";
bookinfo.creditCardExpirationMonth = "12";
bookinfo.creditCardExpirationYear = "2015";
bookad.city = "Seattle";
bookad.stateProvinceCode = "WA";
bookad.countryCode = "US";
bookad.postalCode = "98004";
bookreq.ReservationInfo = bookinfo;
bookad.address1 = "travelnow";
//bookad.city = txtCity.Text;
//bookad.stateProvinceCode = txtState.Text;
//bookad.countryCode = txtCountry.Text;
//bookad.postalCode = txtPostal.Text;
bookreq.AddressInfo = bookad;
bookres = client.getReservation(bookreq);
// HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(client);
Response.Write(bookres.confirmationNumbers);
Response.Write(bookres.departureDate);
Response.Write(bookres.drivingDirections);
Response.Write(bookres.CouponInformationResponse);
but i am still getting the error
The request failed with HTTP status 404: Not Found.
Are you sure your URL is correct? According to the documentation, it should be
https://book.api.ean.com/ean-services/rs/hotel/v3/res
I have a re-usable out of the box sharepoint approval workflow 2010, and I am programmatically approve/reject workflow using the below code snippet inside infopath formcode (2010).
Hashtable ht = new Hashtable();
ht[SPBuiltInFieldId.Completed] = "TRUE";
ht["Completed"] = "TRUE";
ht[SPBuiltInFieldId.PercentComplete] = 1.0f;
ht["PercentComplete"] = 1.0f;
ht["Status"] = "Completed";
ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString
(new CultureInfo((int)task.Web.Language, false),
Strings.WorkflowStatusCompleted, new object[0]);
if (isApprove)
{
ht[SPBuiltInFieldId.WorkflowOutcome] = "Approved";
ht["TaskStatus"] = "Approved";
ht[SPBuiltInFieldId.Comments] = "Approved by Manager";
ht["Comments"] = "Approved by Manager";
}
else
{
XPathNavigator navigatorRejectComments
= this.MainDataSource.CreateNavigator().SelectSingleNode
(XPATH_REJECT_COMMENTS, this.NamespaceManager);
ht[SPBuiltInFieldId.WorkflowOutcome] = "Rejected";
ht["TaskStatus"] = "Rejected";
ht[SPBuiltInFieldId.Comments] = navigatorRejectComments.Value.Trim();
ht["Comments"] = navigatorRejectComments.Value.Trim();
}
ht["FormData"] = SPWorkflowStatus.Completed;
web.AllowUnsafeUpdates = true;
isApproveReject = AlterTask(task, ht, true, 5, 100);
web.AllowUnsafeUpdates = false;
Task Alter method
private static bool AlterTask(SPListItem task, Hashtable htData, bool fSynchronous, int attempts, int millisecondsTimeout)
{
if ((int)task[SPBuiltInFieldId.WorkflowVersion] != 1)
{
SPList parentList = task.ParentList.ParentWeb.Lists[new Guid(task[SPBuiltInFieldId.WorkflowListId].ToString())];
SPListItem parentItem = parentList.Items.GetItemById((int)task[SPBuiltInFieldId.WorkflowItemId]);
for (int i = 0; i < attempts; i++)
{
SPWorkflow workflow = parentItem.Workflows[new Guid(task[SPBuiltInFieldId.WorkflowInstanceID].ToString())];
if (!workflow.IsLocked)
{
task[SPBuiltInFieldId.WorkflowVersion] = 1;
task.SystemUpdate();
break;
}
if (i != attempts - 1)
Thread.Sleep(millisecondsTimeout);
}
}
return SPWorkflowTask.AlterTask(task, htData, fSynchronous);
}
This code works fine, but the comments of the task is not getting altered and it is not included in the e-mail as well. Is there anything wrong with ht["Comments"] that I use? It is not getting altered in task comments. This is SharePoint 2010 workflows and infopath form i am using is also 2010.
Anyone faced similar problem ?
If you need code only for Lists (not for DocLibs) you can use item.ModerationInformation.Status property. Like the the following example:
var url = #"http://server/Lists/ContentApList";
var web = new SPSite(url).OpenWeb();
var list = web.GetList(url);
var item = list.GetItemById(1);
item["MyCheck"] = "test23";
item.ModerationInformation.Status = SPModerationStatusType.Pending;
item.ModerationInformation.Comment = "my coment";
item.SystemUpdate();
But if you want to do it for all list types, you can use internal method UpdateInternal, with the following parameters:
static void UpdateMigrate(SPListItem item)
{
UpdateInternal(item, true, false, Guid.Empty, true, false,false, false, false, false);
}
static void CheckList5()
{
var url = #"http://server/Lists/ContentApList";
var web = new SPSite(url).OpenWeb();
var file = web.GetFile("CheckDocLib/logo.gif");
var item = file.ListItemAllFields;
item["MyComments"] = "test23ddd";
item.ModerationInformation.Status = SPModerationStatusType.Approved;
item.ModerationInformation.Comment = "my coment";
UpdateMigrate(item);
}
You can use examples from this russian blog Item ModerationInformation and SPListItem.UpdateInternal()
To add a comment to a task when you Approve/Reject it, you just need to use the line before AlterTask:
ht["ows_FieldName_Comments"] = comments;
After the task is approved you can see the comments in the Workflow History List.
You can also get all the consolidated comments from a task with:
Hashtable extProperties = SPWorkflowTask.GetExtendedPropertiesAsHashtable(currentTask);
string consolidatedComments = extProperties["FieldName_ConsolidatedComments"].ToString();
Good luck!
I have been trying to bring back 20 results of images using the Bing API. Here's the code:
SearchRequest request = new SearchRequest();
request.AppId = APPID;
request.Query = HttpUtility.HtmlEncode(searchQuery);
request.Sources = new SourceType[] { SourceType.Image };
request.Image = new ImageRequest();
request.Image.Count = 20;
request.Image.Filters = new string[1] { "Size:Medium" };
Now everything on here works, including the Image.Filters property. Just not the Count property. Is there a known bug or am I just missing something here?
I'm not sure really sure about this but I think you are missing setting CountSpecified property. Try this
request.Image = new ImageRequest();
request.Image.Offset = 0;
request.Image.Count = 20;
request.Image.CountSpecified = true;
request.Image.Filters = new string[1] { "Size:Medium" };