|
So how are you doing with it? Have you figured out how simple it is yet?
|
|
|
|
|
Phase1
Well I've managed to construct the HTTP and Soap, send them and parse them using TCPClient and NetworkStream in basic utf8 and ascii with some string handling.
Phase2
Then i added XMLDocument to parse the soap.
Now i've used the HTTPRequest to help out with the constriction of the HTTP. I am still looking fora nice wrapper for SOAP instead of the slightly lower level XML parsing stategy.
Phase 3 - Still looking
Problem is everything i use points to web services. I am not communicating directly with a web service but just want an in memory representation of the soap that makes life a little easier to get/set attributes etc.
Regards
Carl
|
|
|
|
|
That begins to add some clarity to what you are doing. However the following is still confusing:
crandall wrote: I don't want to call a web service, i just want to send http with a soap body and receive the same.
You don't want to call a web service but sending/receiving soap over http is calling a web service. Then you are looking for supporting classes in the BCL to do this (call a web service) but you don't want to use the Web Service classes.
I am at a complete loss to understand what you think you want to do.
|
|
|
|
|
Mike, first things first. SOAP is a protocol, xml based, it has nothing to do with Web Services in it's own right. SOAP messages have been around long before Web Services.
In reality, the TCP connection i am establishing with a remote endpoint will take the data i send and actually call a web service at a later stage.
I am looking for a way of creating soap messages and passing them on via TCP. I DO NOT have a web service that i can call available to me. I do have a TCP listener that will end up sending me a response in a binary structure. However the way i pass data in has to be in the same format a typical Web Service would expect.
That isn't that confusing is it?
Carl
|
|
|
|
|
crandall wrote:
Mike, first things first. SOAP is a protocol, xml based, it has nothing to do with Web Services in it's own right. SOAP messages have been around long before Web Services.
Carl, that post seems to indicate that you don't think I know what SOAP and web services are. If that is so I can only try to assure you that is not the case.
The W3C Web service definition encompasses many different systems, but in common usage the term refers to clients and servers that communicate using XML messages that follow the SOAP standard.
link[^]
crandall wrote: I am looking for a way of creating soap messages and passing them on via TCP. I DO NOT have a web service that i can call available to me. I do have a TCP listener that will end up sending me a response in a binary structure. However the way i pass data in has to be in the same format a typical Web Service would expect.
That isn't that confusing is it?
Mostly yes it is. Once again you state you need to create a SOAP message and transport it as though that is somehow different than what a Web Service does. Hence part of my confusion. Then you say: "I DO NOT have a web service that i can call available to me." as if that is explaining the first part. It doesn't.
Also:
crandall wrote: I do have a TCP listener that will end up sending me a response in a binary structure.
What do you mean binary structure? Following that statement with this:
crandall wrote: However the way i pass data in has to be in the same format a typical Web Service would expect.
So there you mean SOAP. So your "binary structure" has to be a SOAP message? Sorry but what you have stated so far is anything but clear.
As near as I can tell from your posts, the BCL support for Web Services and/or Remoting would provide you with solutions. Trying to use them with your own current TCP transport implementation is problematic and perhaps not possible but I see no reason, so far, that you cannot use the complete BCL solution rather than your own TCP solution.
|
|
|
|
|
Mike, i appreciate you understand SOAP and Web Sevices but you used the terms as if SOAP has no use without them.
The binary structure is what i receive back as a response. - NOT SOAP, not XML, pure binary.
The API i am using expects a SOAP formatted message over HTTP. This leads me to believe under the covers a call to a web service is being made. However this is not exposed to me.
I am accomplishing the goal already, but not very pretty. I am looking to use a portion of the .Net framework than can expose a nice soap object i can use to construct soap messages. It is not completely straight forward. I don't think a web service gives me what need out of the box.
If i try and use any of the SOAP objects thus far, they expect to handle the whole identification and transport associated with Web Services.
Tell me we are on the same playing field now?
Carl
|
|
|
|
|
crandall wrote: Tell me we are on the same playing field now?
Maybe.
crandall wrote: The binary structure is what i receive back as a response. - NOT SOAP, not XML, pure binary.
then...
crandall wrote: The API i am using expects a SOAP formatted message over HTTP
So you need to send a SOAP request but you don't get back a SOAP response? If that is the case then I would imagine ( not certain) that the BCL classes would not be of any use. Seems like what you are presently doing (Phase 2) is an appropriate approach.
|
|
|
|
|
Http Header with body like you describe is a webservice call. SoapExtensions may help you but I don't know if you can use them outside of the context of a webmethod.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Hello,
I am a hobby programmer, writing a small office automation program for my office (translation agency). It's a small database application with several tables on MS SQL Server 2005 (Express). There is a Jobs table which includes individual Project items (i.e. when a translation project includes multiple language pairs, for instance XXXX_EN-TR and XXXX-DE-TR (where XXXX is ProjectID) these individual items (jobs) are written in Jobs table with a foreign key to Projects table's ProjectID).
Upon a button click application should write to Jobs table with following:
string addNewJobQuery = "INSERT INTO Jobs (ProjectID, FileName, SourceLanguage, TargetLanguage, Type, CharCount, PageCount, ApplicableRate, QuotedOn)" + " VALUES (\'" + projectID + "\', \'" + fileName + "\', \'" + srcLangID + "\', \'" + trgLangID + "\', \'" + typeID + "\', \'" + charCount + "\', \'" + pageCount + "\', \'" + applicableRate + "\', \'" + quotedOn + "\'); SELECT SCOPE_IDENTITY()";<br />
Above string includes all mandatory (i.e. where null not allowed) fields of Jobs table and data submitted with this query is appropriate (i.e. decimal is sent to SQL for all decimal fields, Int64 sent for all long fields etc.). But it just don't work. It shoots me an exception "e.message = Error converting data type varchar to numeric."
Following is a list of variables I sent in my last attempt:
ProjectID = 34051 (valid, ProjectID should be long at SQL and Int64 in C# code)
fileName = "D:\\UI\\...\\FileName.doc" (this is string in c# code and text at SQL; shouldn't be this one)
srcLangID = 0 (bigint at SQL, Int64 in c#; this is foreignkey to LanguageID in Languages table; correct)
trgLangID = 1 (biginy at SQL, Int64 in c#; this is foreignkey to LanguageID in Languages table; correct)
typeID = 1 (SQL: bigint, C# Int64, correct - foreignkey to Services tables ServiceID, which is also long)
charCount = 71325 (bigint at SQL, Int64 in C# code. this shouldn't be problem either)
pageCount = 71.325 (decimal at SQL and decimal in C# code)
applicableRate = 25 (alo decimal)
quotedOn = 05.11.2007 17:40:15 (this I obtain with DateTime.Now; should not be problem UNLESS...)
Here is what I seriously suspect; my OS is Turkish language, SQL Server Express is English, Visual Studio is also English. Could it be:
1) DateTime returning different format date/time (. instead of /); OR
2) Different decimal separators (. instead of ,)
OH, wait, when I type above string (removing quotemarks and paranthesis ofcourse) in a query, it all works fine... But in C# it just won't.
Could anyone come up with a hint? Thanks in advance & Kind Regards
Haluk
|
|
|
|
|
Hey Haluk,
Some 'hints'. If you are inserting a value into an integer column, you shouldn't put in in quotes:
insert into MyTable(Col1) values ('1')
should be just:
insert into MyTable(Col1) values (1)
So make sure that you don't parenthesize integers.
Try to break that huge insert statement into something more readable - ideally a parameterised stored procedure where you can add the parameters one by one. If you don't want to do that then try StringBuilder to String.Format to make it more readable.
One last thing - it look like you're escaping single quotes (\'). You don't need to do this. You only need to escape double quotes (\")
Hope that helps.
Regards,
Rob Philpott.
|
|
|
|
|
Hello Rob,
Thanks for helping me. You're right about all your comments. I have removed single quotes but this time I get another exception telling me there are more fields in VALUES than there is in INSERT. I checked what is sent to SQL, it is as follows:
INSERT INTO Jobs (ProjectID, FileName, SourceLanguage, TargetLanguage, Type, CharCount, PageCount, ApplicableRate, QuotedOn) VALUES (34058, 'D:\UI\Projects\2007\34058 (Company)\Some Document.doc', 0, 1, 1, 71325, 71,325, 25, '05.11.2007 19:56:19'); SELECT SCOPE_IDENTITY();
As you can see 71.325 is written as 71,325 and I suspect SQL is translating this as 71 for one field and 325 for another field; thus there is more VALUES than INSERTs...
PS: once I get this running, I'll optimize it and I took note of your comments about huge string and readibility
|
|
|
|
|
For your DateTime issue, you could use the sql getdate() funtion inside your SQL. That would eliminate translation issues as SQL would enter dates that it likes.
Finally for debugging reasons, can you output your addNewJobQuery after it is set into the message so we can see the direct values. That might help troubleshoot your issue.
Hogan
|
|
|
|
|
Hello There,
Here it is:
INSERT INTO Jobs (ProjectID, FileName, SourceLanguage, TargetLanguage, Type, CharCount, PageCount, ApplicableRate, QuotedOn) VALUES (34058, 'D:\UI\Projects\2007\34058 (Company)\Sample Document.doc', 0, 1, 1, 71325, 71,325, 25, '05.11.2007 19:56:19'); SELECT SCOPE_IDENTITY();
It is right there, 71,325 is actually 71.325 in English (71325 / 1000). I suspect that is the cause of all this.
|
|
|
|
|
Yep, it looks like you found the issue. Try overriding ToString() method and convert it to the correct format for SQL Server.
Hogan
|
|
|
|
|
Hogan Hi,
Overriding ToString is not problem but... All calculations are made in the program; storing what is inappropriate for OS regional settings would complicate my calculations. In fact, changing the field type to string and storing Turkish notation decimal (i.e. 71,325) would be a workaround; but ideally there should be a real solution for this.
Isn't there any localization settings in MS SQL server?!?
|
|
|
|
|
Two thoughts for you...
First, I know that you can localize strings in SQL server by setting their "collation sequence". That is useful for the order by for a specific language. But you want to be dealing with numbers here.
Second, from what I understand, the numbers you see are all stored in memory the same way. When we output them, they are filtered by region. With that being said, you should be able to put numbers in and pull them out without issue. I would try the following.
When you are creating your SQL try this. (pseudo code below)
decimal calculatedNumber = 71,325
In your SQL statement use the following statement to convert your number to an acceptable format
<br />
calculatedNumber.ToString().Replace(",",".")<br />
When you are getting the value back out of the database, you should be able to just do a straight assignment and get the value as you need it.
<br />
calculatedNumber = (decimal) dataReader["CalculatedNumberField"];<br />
Hope this helps.
Hogan
|
|
|
|
|
The most apparent thing here is that you are using direct SQL to achieve this. You should use a stored procedure instead because it is better for you with regards to SQL Injection Attacks and also it takes care of the mappings for you.
CREATE PROCEDURE dbo.SaveJobs
@ID BIGINT OUT,
@ProjectID BIGINT,
@FileName NVARCHAR(255),
@SourceLanguage BIGINT,
@TargetLanguage BIGINT,
@Type BIGINT,
@CharCount BIGINT,
@PageCount DECIMAL(10,4),
@ApplicableRate DECIMAL(10,4),
@QuotedOn DATETIME
AS
INSERT INTO JOBS(ProjectID, FileName, SourceLanguage, TargetLanguage, Type, CharCount, PageCount, ApplicableRate, QuotedOn)
VALUES (
@ProjectID,
@FileName,
@SourceLanguage,
@TargetLanguage,
@Type,
@CharCount,
@PageCount,
@ApplicableRate,
@QuotedOn)
SET @ID = SCOPE_IDENTITY() Then you create a SqlCommand in your C# and fill in your parameters with the relevant values.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thank you. Much appreciated.
|
|
|
|
|
Hi,
if you had to search 50000 lines of code for the word example as fast as possible, with every kind of whitespace in the line, which method would you prefer.
REGEX
or
myString.Trim() == "example"
|
|
|
|
|
May be Regex, which compiled into assembly, but I'm not sure. It's better to test.
|
|
|
|
|
error1408 wrote: if you had to search 50000 lines of code for the word example as fast as possible, with every kind of whitespace in the line, which method would you prefer.
REGEX
or
myString.Trim() == "example"
In this case RegEx would be the only one that works.
The second example would only ever return false.
|
|
|
|
|
string.IndexOf
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Why not try it out for yourself and find out. Create a document containing the phrase "The quick brown fox jumps over the lazy fox" by cutting and pasting repeatedly; it won't take you long to knock up a 50000 line document with this in. Now, put a seed word in the middle somewhere - call it seed for instance.
Then, run a program that uses both versions against this document and see which method is faster.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Ok i wrote a little app that compares the two methods.
I found out, that testing a file with 60000 lines 30 times took my pc about a second with this method:
<br />
using (StreamReader rIn = new StreamReader("test.txt"))<br />
{<br />
string line = "";<br />
while ((line = rIn.ReadLine()) != null)<br />
{<br />
if (line.Trim() == "{{{tcl")<br />
{<br />
return true;<br />
}<br />
}<br />
rIn.Close();<br />
<br />
}<br />
return false;<br />
and about 9 seconds with the regex:
<br />
using (StreamReader rIn = new StreamReader("test.txt"))<br />
{<br />
string line = "";<br />
Regex reg = new Regex(@"\s*\{\{\{tcl\s*");<br />
while ((line = rIn.ReadLine()) != null)<br />
{<br />
if (reg.IsMatch(line))<br />
{<br />
return true;<br />
}<br />
}<br />
rIn.Close();<br />
}<br />
return false;<br />
Thats a BIG difference.
|
|
|
|
|
A well deserved 5 for answering your own question.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|