Solved

Which directive to use

Posted on 2013-12-18
37
504 Views
Last Modified: 2014-01-16
Hi,
I get this
Error    7    The type or namespace name 'ExchangeServiceBinding' could not be found (are you missing a using directive or an assembly reference?)    C:\App4\App4\Default.aspx.cs    32    33    App4

due to this line

        static void CreateEmail(ExchangeServiceBinding esb)

Open in new window


which directive should I use for it?
0
Comment
Question by:HuaMinChen
  • 19
  • 18
37 Comments
 
LVL 9

Expert Comment

by:gt2847c
ID: 39728340
The error is telling you that the compiler doesn't know what the object "ExchangeServiceBinding" is.  The error message is asking if you left out a DLL reference or did not add a "using" directive in your source file.

The using directive at the top of a C# file defines a shortcut for object naming:

For Example, the DateTime object fully qualified is System.DateTime.  If, at the top of your C# file, you specify:
using System;

Open in new window

You are able to use DateTime without the 'System.' prefix.  If you didn't have the using System; directive you would have to fully qualify it as System.DateTime or you would get the error you listed above.

Alternatively, if you are attempting to reference an object that is not part of the standard set of DLLs that are automatically provided for you at compile time, the compiler will be unable to locate the object you are referencing (ExchangeServiceBinding in this case) and will emit that error.

Best I'm able to tell from what snippet you provided, you may not have generated the Web Service Proxy for the Exchange Web Service, in which case you'd get that error.  These two pages may be of assistance:

Setting Up the ExchangeServiceBinding Proxy Class
Creating a Proxy Reference By Using Visual Studio 2005 or Visual Studio 2008
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39728351
Which directive should I use to avoid the problem?
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39728356
Did you add a reference in your project to the Exchange Web Service Assembly?

Did you add
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;

Open in new window

0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39728362
Thanks.
I am using VS 2013 and I am not able to choose

Microsoft.Exchange

in that.
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39728371
Did you create the Web Service Reference for the Exchange Server?

Right click your project name in the Solution Explorer.
Select "Add Service Reference"
Click the Advanced button below the Namespace: textbox
Click the Add Web Reference... button at the bottom left
In the URL, fill in the details for your Exchange Server (https://myserver.mydomain.com/EWS/Exchange.asmx)
Fill in any credential prompts it may pop up.
Fill in the name in "Web reference name:" - this will be the name you reference in your code.

If you specify say, "Exchange" in the web reference name, then add
using Exchange;

Open in new window

that may do what you are looking for.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39728382
Many thanks. what to choose next, below?

mail.my-friend.co

is what I've put in the MX record and my Exchange server is working fine.
t616.png
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39728389
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39728398
Sorry, I get this
t617.png
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39728404
Are you sure the URL you provided is an Exchange 2010 or later server?  If not, it won't work.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39728407
Yes, I am using Exchange 2010.
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39728447
Try "https://mail.myfriend.co/EWS/Exchange.asmx" in a browser and see if you get anything.  If you get an error or nothing, then there may be a problem with the server you're attempting to connect to.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39728470
Yes, I get this below. But

mail.my-friend.co

is the one I put to my MX record and my Exchange server is working fine.
t618.png
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39729405
Given the error message from your browser, either that front end server is restricting your access or something else may be wrong.  See what you get with this:

https://mail.my-friend.co/owa
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39735276
I also get the same problem to go to
https://mail.my-friend.co/owa

but it is fine to go to this
https://localhost/owa
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39737029
If localhost works, try this in your browser and see what you get:

https://localhost/EWS/Exchange.asmx
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39737256
Thanks. is it fine with the attached?
t619.png
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39737257
You might want to change the "Web reference name" in that  dialog to something more descriptive than "localhost" as the object will be referenced by that name.  Other than that, it should create the proxy you are trying to reference with your code.  If you want to reference it by the short names, you'll need to add a "using" statement with the name you specify in the "Web reference name".
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39737268
Sorry, how about I get the attached with that?
t620.png
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 9

Expert Comment

by:gt2847c
ID: 39737273
Several things... First, it appears you're using a self-signed certificate, which is OK for development but not really what you want for production (something to keep in mind for later).  Second, you're referencing the server by localhost rather than the name of the server which would appear to be WIN-AIGPMD763AL.  Since the name localhost is not the same as WIN-AIGPMD763AL the security check on the SSL certificate is letting you know of the mismatch.  That error is to warn you in case you think you're going to say your banking site and someone has hijacked it to go somewhere else.  In this case, since it's your server, its not a problem.  Third, WIN-AIGPMD763AL appears to be the automatically created name Windows server uses when you create a new server.  Did you intend to leave it that way?  Last item, if you are planning on others using your server by the name mail.my-friend.co, all of those attempting to use your server are going to get a similar error message telling them that the certificate was issued to WIN-AIGPMD763AL and not mail.my-friend.co.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39737283
Then how to correct it and ensure no similar message later on?
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39737307
I'll try to address them point by point...

Self-signed certificates will always give you some form of error on a browser as they are not signed by a "trusted" authority.  Self-signed certs are typically intended to give you a working development environment without having to pay for a cert.  If you want a certificate that doesn't get flagged by browsers, you'll need to get a certificate signed by a recognized certificate authority (Entrust, Go Daddy, etc).  Here's a web page that lists  the authorities Microsoft distributes in their trusted root CA list

The last three items are somewhat interrelated.  In the dialog box, you should reference the server based on the expected server name rather than localhost.  Localhost will only work on the server itself.  If you use a fully qualified domain name (mail.my-friend.co), the code should work anywhere you can resolve that name.  Since you tried the fully qualified name unsuccessfully in the earlier steps, that means the DNS server your server is referencing is not able to resolve mail.my-friend.co back to your server.  That could be several causes for that:

- The DNS server is unable to resolve the name mail.my-friend.co - to fix it, add the name to the DNS server with the appropriate IP address (if you're using private address space, see the next point)

- The IP address it does resolve to is an external address and you are using private address space behind a firewall or router - you would either have to have an internal DNS server that can resolve the name for you to an internal address (split-DNS) or have the firewall or router be able to reroute the external address back to your server.  Split-DNS is the most common solution.

The server name is a done deal at this point.  I did a quick check and what I found on Microsoft's various sites state that changing the name of an existing Exchange server is a no-go.  They say the method to change the name goes like:  Uninstall Exchange, change the server name, re-install Exchange.  Alternatively, build another Exchange server with the name you wanted.  

The last item can be fixed several ways.  The typical method is to use the name you desire (mail.my-friend.co) as the name on the certificate signing request you send to the certificate authority to sign.  Other ways to do it would be to have a certificate that allows multiple names or works for the entire domain (*.my-friend.co).  Those options are often dependent on the certificate type and the costs for those certs vary.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39737413
Many thanks. should I ask for a certificate to

mail.my-friend.co

from Godaddy? I have only public IP address to the server.
0
 
LVL 9

Assisted Solution

by:gt2847c
gt2847c earned 145 total points
ID: 39737422
If you're hosting this as a for profit site, I'd shop around for the best insurance policy... If you're doing this for a non-profit situation, then find the best price for a cert...  Go Daddy has some cheap ones, but not much on the liability side.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39737438
which is the insurance policy?
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39737443
Network Solutions (for example) calls it their Guarantee.  Effectively, it is saying that if a breach of your site happens due to a problem with their certificate, they will compensate your customers up to the limit of the guarantee.  GoDaddy has a guarantee specified in slightly different terms.  The limits are dependent on things like how carefully the issuing Certificate Authority checks the ownership of the domain and how much you pay them for the certificate.  As to how much this means in a court of law, I have no real idea, you'll have to consult a lawyer on that...

Upon thinking about it, if your site isn't very tightly (an provably) secured, the guarantee probably isn't worth a lot...
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39737461
but I should ask for a certificate from Godaddy, right?
0
 
LVL 9

Assisted Solution

by:gt2847c
gt2847c earned 145 total points
ID: 39737474
That's up to you.  There are a lot of different certificate authorities around.  GoDaddy is one of them, but by no means the only one out there.  I have had a certificate signed by them I use for my own Exchange site, but as I am the only user on it, I went for the cheapest certificate I could find (it was worth the $25 US to skip the annoying SSL certificate notices for a self-signed cert).  I also don't renew it as the renewal costs more than the original certificate did (they try to enroll you in auto-renewal and you have to opt out of that).  So when I need a new one, I let the old one expire and buy a new one.  Also, they try and sell you lots of add on extras which is kind of annoying.  

As to what the "best" option for your site, that's something you will need to decide...
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39737758
Many thanks. which company is giving the cheapest certificate?
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39738210
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39741364
Thanks. Do you think a

StartSSL

will resolve my problem?
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39742103
Having a certificate signed by a trusted authority will make the warning messages go away if that's what you are asking.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39742999
But there are several kinds of certificate? Is it to choose

StartSSL

? Thanks
0
 
LVL 9

Accepted Solution

by:
gt2847c earned 145 total points
ID: 39743032
Here is the comparison chart...

From there, you will need to decide which features you want and that should help you determine which certificate to select.  Here is their Frequently Asked Questions page.

Per Wikipedia's description, here are the different classes and their intended uses:
Class 1 for individuals, intended for email.
Class 2 for organizations, for which proof of identity is required.
Class 3 for servers and software signing, for which independent verification and checking of identity and authority is done by the issuing certificate authority.

StartSSL will give you a free Class 1 cert, but that's not really intended to run a business with, it's mostly for private personal use.  The Class 2 or 3 certificate would be what you want if you're doing this as a business.

Extended Validation certificates are more commonly used for transaction sites (credit card, etc).  

We've really gone on a tangent from your original question...  If you need more help than the above, you should probably open a separate question for it...
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39752897
So I should have Class 3 certificate, right?
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39774009
That answer is dependent on what you're doing with the site.  It is a judgement call you will need to make.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39787452
Can I say "Class 2" can be fine to use, if it is for the site of a private comany?
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39787454
That would probably be sufficient.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now